简体   繁体   English

我必须通过WPF中的接口来实现所有usercontrol属性吗?

[英]Do i have to implement all usercontrol properties by interface in WPF?

I'm programming a bunch of WPF usercontrols (not CommonControls!) using an Interface for the common properties like the alignments or the Content (depending on the control; TextBox returns the Text, and Label the Content per example). 我正在使用一组接口对WPF用户控件(不是CommonControls!)进行编程,以使用通用属性(如对齐方式或内容)(取决于控件;取决于控件; TextBox返回Text,并为每个示例标记Content)。 Now i get to controls like the Checkbox, which have the not so common property IsChecked. 现在,我进入诸如Checkbox之类的控件,它们具有不太常见的属性IsChecked。 Do i have to implement this property by the Interface or is it allowed to program it in the usercontrol itself? 我是否必须通过接口实现此属性,或者是否可以在用户控件本身中对其进行编程?

I hope you're talking about binding a property to a view model or directly mentioning the property value in the xaml itself. 我希望您正在谈论将属性绑定到视图模型,或者直接在xaml本身中提及属性值。

It actually depends upon your requirement. 它实际上取决于您的要求。 We normally bind a property value to a view model or code behind when that property needs to be checked by certain conditions and then to be set. 通常,当需要通过某些条件检查然后设置属性值时,通常会将属性值绑定到视图模型或代码。 If you're sure of the property's value, you can set it in xaml itself. 如果您确定该属性的值,则可以在xaml本身中进行设置。

For example if you want to set a textbox's IsEnabled property, and you're sure that the text box is always editable. 例如,如果您想设置文本框的IsEnabled属性,并且确定该文本框始终可编辑。 Then set it as true in xaml itself. 然后在xaml本身中将其设置为true。 But if you're text box need to be enabled during an event is handled, bind it to a property in view model and set it to true during the event trigger. 但是,如果您需要在处理事件期间启用文本框,请将其绑定到视图模型中的属性,并在事件触发期间将其设置为true。

Okay, i have to guess it was a dumb question. 好吧,我不得不猜测这是一个愚蠢的问题。 But after eight hours you don't know anymore, if you're Hillary or Donald. 但是八小时后,您不再是希拉里还是唐纳德了。

The answer is: An Interface can inherit from another and implement all members from the "parent" interface. 答案是:接口可以从另一个接口继承并实现“父”接口的所有成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM