C# 如何从XAML绑定到代码隐藏中定义的属性
如何将C# 如何从XAML绑定到代码隐藏中定义的属性,c#,wpf,xaml,C#,Wpf,Xaml,如何将TextBox的Text属性绑定到代码隐藏中定义的FoundationHeightclr属性 xaml <TextBox Text="{Binding FoundationHeight}"/> 使用相对资源 如果为用户控件定义了代码隐藏: <TextBox Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=Foundat
TextBox
的Text
属性绑定到代码隐藏中定义的FoundationHeight
clr属性
xaml
<TextBox Text="{Binding FoundationHeight}"/>
使用
相对资源
如果为用户控件定义了代码隐藏:
<TextBox Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=FoundationHeight}" />
使用
相关资源
如果为用户控件定义了代码隐藏:
<TextBox Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=FoundationHeight}" />
您可以将这一行添加到窗口的构造函数中
public AssignColumnPropertiesWindow()
{
InitializeComponent();
DataContext = this;
FoundationHeight = 60;
}
您的
绑定将起作用您可以将这一行添加到窗口的构造函数中
public AssignColumnPropertiesWindow()
{
InitializeComponent();
DataContext = this;
FoundationHeight = 60;
}
您的绑定将起作用不客气;)如果答案对你有效,请确保你接受它(不客气;)如果答案对你有效,请确保你接受它