Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从XAML绑定到代码隐藏中定义的属性_C#_Wpf_Xaml - Fatal编程技术网

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;
}
您的
绑定将起作用

不客气;)如果答案对你有效,请确保你接受它(不客气;)如果答案对你有效,请确保你接受它