我正在尝试将一个非常简单的属性绑定到一个TextBlock,但我必须在代码隐藏(C#)中完成所有的工作。
我想要做的是:
public string SomeText { get; set; }
在我尝试TextBlock上的绑定之后:
Binding myBinding = new Binding(SomeText);
myTextBlock.SetBinding(TextBlock.TextProperty, myBinding);
如何保持TextBlock的Text属性与属性SomeText
相同。
发布于 2012-04-13 05:03:40
使用BindingOperations
Binding binding = new Binding();
binding.Path = new PropertyPath("SomeText");
binding.Source = sourceObject; // view model?
BindingOperations.SetBinding(theTextBlock, TextBlock.TextProperty, binding);
https://stackoverflow.com/questions/10131637
复制相似问题