Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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
Wpf 代码隐藏文本块中的绑定字符串属性_Wpf_Binding_Code Behind - Fatal编程技术网

Wpf 代码隐藏文本块中的绑定字符串属性

Wpf 代码隐藏文本块中的绑定字符串属性,wpf,binding,code-behind,Wpf,Binding,Code Behind,我试图将一个非常简单的属性绑定到TextBlock,但我必须在代码隐藏(C#)中完成所有工作 我想做的是: public string SomeText { get; set; } 在我尝试对TextBlock进行绑定之后: Binding myBinding = new Binding(SomeText); myTextBlock.SetBinding(TextBlock.TextProperty, myBinding); 如何使TextBlock的Text属性与属性SomeText使用B

我试图将一个非常简单的属性绑定到TextBlock,但我必须在代码隐藏(C#)中完成所有工作

我想做的是:

public string SomeText { get; set; }
在我尝试对TextBlock进行绑定之后:

Binding myBinding = new Binding(SomeText);
myTextBlock.SetBinding(TextBlock.TextProperty, myBinding);
如何使TextBlock的Text属性与属性
SomeText

使用BindingOperations保持一致

Binding binding = new Binding();
binding.Path = new PropertyPath("SomeText");
binding.Source = sourceObject;  // view model?

BindingOperations.SetBinding(theTextBlock, TextBlock.TextProperty, binding);
FrameworkElement已经完成了这项工作,它将更短。这里唯一的问题是绑定路径的设置。