c# - WPF Dependency Property for Custom Control -
I am a bit of a mess with setting up a dependency property for the
How do custom controls.
I have created a custom control, so it is out of control class.
public class CustControl: Control {static CustControl () {DefaultStyleKeyProperty.OverrideMetadata (typeof (CustControl), New FrameworkPropertyMetadata (typeof (CustControl))); }}
To set the dependency property, I must register it within a class that should be obtained from the dependency object. So it should be a class:
class CustClass: DependencyObject {public static only DependencyProperty MyFirstProperty read = DependencyProperty.Register ( "MyFirst", typeof (string), typeof (CustControl), New PropertyMetadata ("")); Public string myfst {get {return (string) GetValue (MyFirstProperty); } Set {Set Value (MyFastProperty, Value); }}}
How can I now install MyFirst property as a dependency asset for the custodian of the custodian?
dependence to establish property I should be a class derived in this register In order to have the object from dependency, then it should be another class:
No, it should not be. Control
has already come from dependency object
. Since the legacy, this is a sub type of CustControl
as also dependency object
. Just put it all CustControl :
public class CustControl: Control {static CustControl () {DefaultStyleKeyProperty.OverrideMetadata (typeof (CustControl), New FrameworkPropertyMetadata (typeof (CustControl ))); } Public static only DependencyProperty MyFirstProperty read = DependencyProperty.Register ( "MyFirst", typeof (string), typeof (CustControl), New PropertyMetadata ( "")); Public string myfst {get {return (string) GetValue (MyFirstProperty); } Set {Set Value (MyFastProperty, Value); }}}
Comments
Post a Comment