我有一组需要具有一些类似属性的UserControl。因此,我定义了一个UserControl的抽象子类,它定义了这些属性,并更新了.xaml.cs和.g.cs文件以继承此基类。所有编译良好,运行良好。大!但是.... g.cs文件是生成的并且将被重新生成,那么我如何告诉Blend或Visual Studio继承我的基类而不是UserControl呢?
答案 0 :(得分:6)
您需要稍微更改XAML以使UserControl声明前缀为命名空间:
<local:MyBaseControl x:Class="MyNameSpace.MyControl"
xmlns:local="clr-namespace:MyNameSpace"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Content -->
</local:MyBaseControl>
MyNameSpace是你的命名空间(呃!),MyBaseControl是你的基类,MyControl是你继承MyBaseControl的控件。 x:Class部分不需要在同一个命名空间中,我只是保持它与示例相同。