Definition
in z.b. UserControlpublic partial class MyUserControl : UserControl
{
public static readonly DependencyProperty HeaderProperty =
DependencyProperty.Register("Header", typeof(string), typeof(MyUserControl ), new FrameworkPropertyMetadata("DefaultHeaderText"));
//zusätzlich um einfacheen Setzten / Lesen der Dep.property:
public string Header
{
get => (string)GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}
...
Binding
im Usercontrol:<UserControl x:Name="myUserControl"
<TextBlock Text="{Binding Header, ElementName=myUserControl}"/>
wichtig mit ElementName=myUserControl wird richtiger Context hergestellt
No comments:
Post a Comment