继承自UserControl抽象子类 [英] Inheriting from a UserControl abstract subclass

查看:175
本文介绍了继承自UserControl抽象子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a set of UserControls that need to have a few similar properties. Thus I have defined an abstract subclass of UserControl that defines these properties and updated the .xaml.cs and .g.cs files to inherit from this base class. All compiles well and runs well. Great! But.... .g.cs files are generated and will be regenerated, so how do I tell Blend or Visual Studio to keep inheriting from my base class rather than UserControl?

推荐答案

您需要稍微更改XAML以使用名称空间为UserControl声明添加前缀:

You need to change the XAML a bit to prefix the UserControl declaration with a namespace:

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

Where MyNameSpace is your namespace (duh!), MyBaseControl is your base class and MyControl is your control that inherits from MyBaseControl. The x:Class part doesn't need to be in the same namespace, I've just kept it the same for the example.

更多信息这里这里

这篇关于继承自UserControl抽象子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆