Last active
December 16, 2019 13:29
-
-
Save Axemasta/50091d814957bd8aeb08510eaa5e833a to your computer and use it in GitHub Desktop.
WPF Custom Properties User Control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleUserControl : UserControl | |
{ | |
#region Properties | |
#region - Bindable Property Declaration | |
public static readonly DependencyProperty ExampleTextProperty = | |
DependencyProperty.Register( | |
nameof(ExampleText), | |
typeof(string), | |
typeof(ExampleUserControl | |
), | |
new UIPropertyMetadata( | |
string.Empty, | |
ExampleTextPropertyChanged) | |
); | |
#endregion - Bindable Property Declaration | |
#region - Bindable Properties | |
public string ExampleText | |
{ | |
get { return GetValue(ExampleTextProperty).ToString(); } | |
set { SetValue(ExampleTextProperty, value); } | |
} | |
#endregion - Bindable Properties | |
#region - Class Properties | |
private Button _button; | |
#endregion - Class Properties | |
#endregion Properties | |
public ExampleUserControl () | |
{ | |
_button = new Button() { Content = "Placeholder" }; | |
this.Content = _button; | |
} | |
#region Methods | |
#region - Binded Property Changed Methods | |
private static void ExampleTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | |
{ | |
ExampleUserControl | |
control = (ExampleUserControl | |
)d; | |
control._button.Content = d.GetValue(ExampleTextProperty) as string; | |
//string value = d.GetValue(ExampleTextProperty) as string; | |
//_button.Content = value; | |
} | |
#endregion - Binded Property Changed Methods | |
#endregion Methods | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment