Do i have to implement all usercontrol properties

2019-08-27 07:49发布

问题:

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). Now i get to controls like the Checkbox, which have the not so common property IsChecked. Do i have to implement this property by the Interface or is it allowed to program it in the usercontrol itself?

回答1:

I hope you're talking about binding a property to a view model or directly mentioning the property value in the xaml itself.

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.

For example if you want to set a textbox's IsEnabled property, and you're sure that the text box is always editable. Then set it as true in xaml itself. 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.



回答2:

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.