2

我有一组需要具有一些类似属性的用户控件。因此,我定义了 UserControl 的抽象子类,它定义了这些属性,并更新了 .xaml.cs 和 .g.cs 文件以从这个基类继承。一切编译良好,运行良好。伟大的!但是.... .g.cs 文件已生成并将重新生成,那么我如何告诉 Blend 或 Visual Studio 继续从我的基类而不是 UserControl 继承?

4

1 回答 1

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 部分不需要在同一个命名空间中,我只是在示例中保持相同。

更多信息在这里这里

于 2009-03-09T08:45:24.503 回答