我有一个情况,其中类层次结构是这样的:
+---------------+
| UIElement |
|---------------| +----------------------+
| ... | | My Windows Application
| SomePropert{} | |----------------------|
| |<---+ |+--------------------+|
| | | ||MyUserControl ||
+---------------+ | ||--------------------||
+--------------+-----+ || ||
|FrameWorkElement | |+--------------------+|
|--------------------| |//Want to use |
| ... |<-+ |// SomeProperty; |
+--------------------+ | | |
+-----------+-+ | |
|Control | | |
|-------------| +----------------------+
| ... |<---+
+-------------+ |
+-----------+---+
| UserControl |
|---------------|<---+
| ... | |
+---------------+ |
+----------+-------+
| MyUserControl |
|------------------|
| SomeProperty{} |
| //Want to override
| |
+------------------+
现在,在我的应用程序中(以及所有其他可以导出此MyUserControl的应用程序中),我可以设置由MyUserControl
类处理而不是UIElement
的SomeProperty
吗?
我现在正在通过创建一个指向MyUserControl对象并将其分配给我在xaml页面中添加的控件来实现这一点。所以现在看起来像这样:
MyUserControl newControl = new MyUserControl();
web = windowsPhoneControl11; //windowsPhoneControll1 is the
//one that I added from toolbox.
// i.e., mycustomecontrol added from toolbox.
现在由于我正在使用“new”,所以它被覆盖了。但是当我导出此控件时,我不能指望用户创建一个新对象并将其分配给在xaml页面中使用的控件。
那么,是否还有其他方式可以覆盖此属性,以便MyUserControl类处理该属性的赋值而不是UIElement类?我的意思是,让MyUserControl具有设置此属性的控制权,因为我需要检查某些值然后再进行分配。如果它不是期望的值,则需要将其设置为默认值。
PS:非常抱歉这个问题很长,但我无法更加精确地表达它,也找不到与此相关的其他问题。这是WindowsPhoneApp,而不是普通的Windows应用程序。
MyUserControl newControl = new MyUserControl();
这行代码的含义是什么? - Tigran