从UserControl派生 [英] Derive from UserControl

查看:77
本文介绍了从UserControl派生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我用视图虚拟方法创建了一个用户控件,因此我可以从它们派生并在需要的地方使用标准行为.
现在XAML告诉我
错误1部分声明``xxx.View.UserControl1''的名称不能指定不同的基类... \ View \ UserControl1.xaml.cs 20 26"

是否可以这样做?我确实使用了接口,但希望有一个预定义的行为,可以在需要时将其覆盖.

将不胜感激!
在此先感谢您

Hi again!

I created a usercontrol with a view virtual methods so I could derive from them and use the standard behaviour where needed.
Now XAML tells me
"Error 1 Partial declarations of ''xxx.View.UserControl1'' must not specify different base classes ...\View\UserControl1.xaml.cs 20 26"

Isn''t it possible to do it this way? I do use interfaces but wanted to have a predifined behaviour which can be overwritten where needed.

Help would be appreciated!
Thank you in advance

推荐答案

哦,亲爱的-您在这里遇到了一个相当普遍的问题,这与WPF生成支持类以实际将控件映射到其中的方式有​​关(它称为xxxx.g.cs,其中xxx是您的班级).您需要做一些工作来解决此问题,并此处'的 [ ^ ]指向您可能会觉得有用的条目的链接.

Oh dear - you''ve hit a fairly common problem here, and it''s to do with the way WPF generates a backing class to actually map your controls in (it''s called xxxx.g.cs where xxx is your class). You need to do a bit of work to get round this, and here''s[^] a link to an entry you might find useful.


您好,

实际上,该解决方案非常容易.

当您从usercontrol派生时,必须在后面的代码中进行操作,而在XAML中,必须通过派生类之一更改标记.因此,解决方案是:
1)声明控件的XML名称空间(在旧的UserControl标记中)
2)将"UserControl"标签更改为YourXMLNameSpace:YourDerivedControl一个

就这样
Hello,

The solution is quite easy in fact.

When u derive from usercontrol, you have to do it in the code behind and in the XAML you have to change the tag by the one of your derived class. SO the solution is :
1) Declare the XML namespace of your controls (in the old UserControl tag)
2) Change the "UserControl" tag to the YourXMLNameSpace:YourDerivedControl one

That''s all


这篇关于从UserControl派生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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