简体   繁体   English

共享xaml.cs文件

[英]Share xaml.cs files

I'm using a shared library to share some of my code. 我正在使用共享库来共享一些代码。 Is it possible to share the xaml.cs files for XAML page templates in the same way by putting them into the shared library? 是否可以通过将XAML页面模板的xaml.cs文件放入共享库中来共享它们?

You can extend UserControl and reuse that class in your xaml.cs files: 您可以扩展UserControl并在xaml.cs文件中重用该类:

public class MyBaseControl : UserControl
{
    // shared functionality
}

and your XAML files look like this: 您的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>

and your xaml.cs files: 和您的xaml.cs文件:

public sealed partial class CoolUserControl : MyBaseControl
{
   public CoolUserControl()
   {
      InitializeComponent();
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM