我正在尝试在代码隐藏中设置数据绑定,但它不起作用。
当我在XAML中这样做时:
<Label x:Name="lblSelectedItem" Margin="0,0,5,5" DockPanel.Dock="Left" Content="{Binding (Canvas.Left),ElementName=Ming}"></Label>
它完美地工作,但是当我这样做时:
var X1Binding = new Binding("Canvas.Left") { ElementName="Ming"};
BindingOperations.SetBinding(lblSelectedItem, ContentProperty, X1Binding);
它没有任何价值。
如何正确执行此操作?
最佳答案
像这样在Canvas.Left
周围使用括号:
var X1Binding = new Binding("(Canvas.Left)") { ElementName = "Rect" };
BindingOperations.SetBinding(Lbl1, Label.ContentProperty, X1Binding);
关于c# - 后台代码中的数据绑定(bind)拒绝工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36394335/