public partial class FolderComponent : UserControl { public static readonly DependencyProperty FolderNameProperty = DependencyProperty.Register( nameof(FolderName), typeof(string), typeof(FolderComponent), new FrameworkPropertyMetadata( "", FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(OnFolderNameChanged), null), null); public FolderComponent() { InitializeComponent(); } public string FolderName { get { return (string) GetValue(FolderNameProperty); } set { SetValue(FolderNameProperty, value); } } private static void OnFolderNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FolderComponent uc = (FolderComponent) d; string oldValue = (string) e.OldValue; string newValue = (string) e.NewValue; uc.TextBlockFolderName.Text = newValue; } }
References
https://docs.microsoft.com/en-us/dotnet/desktop/wpf/advanced/custom-dependency-properties?view=netframeworkdesktop-4.8
https://stackoverflow.com/questions/17629945/how-to-create-a-bindable-property-in-wpf
https://stackoverflow.com/questions/29763254/what-is-the-proper-method-for-creating-a-bindable-property-on-a-user-control-in