分享xaml.cs文件

时间:2017-04-20 21:48:14

标签: c# xaml uwp

我正在使用共享库来共享我的一些代码。是否可以通过将XAMl页面模板放入共享库来以相同的方式共享xaml.cs文件?

1 个答案:

答案 0 :(得分:2)

您可以扩展UserControl并在xaml.cs文件中重用该类:

public class MyBaseControl : UserControl
{
    // shared functionality
}

并且您的XAML文件如下所示:

<local:MyBaseControl x:Class="MyApp.CoolUserControl"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:local="using:MyApp">
    <Grid>

    </Grid>
</local:MyBaseControl>

和你的xaml.cs文件:

public sealed partial class CoolUserControl : MyBaseControl
{
   public CoolUserControl()
   {
      InitializeComponent();
   }
}
相关问题