情况很简单,我在TextBlock控件后面的代码中进行了多次绑定(bind),如下所示:

TextBlock tb = new TextBlock();
tb.VerticalAlignment = VerticalAlignment.Center;
tb.HorizontalAlignment = HorizontalAlignment.Center;

MultiBinding multiTbBinding = new MultiBinding();
multiTbBinding.StringFormat = "{}{0} + {1}";
multiTbBinding.Bindings.Add(new Binding()
{
    Path = new PropertyPath("PraceLamania[" + vm.PraceLamania.IndexOf(dpl) + "].DPL_Temperatura"),
    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
    Mode = BindingMode.OneWay,
    Source = vm
});
multiTbBinding.Bindings.Add(new Binding()
{
    Path = new PropertyPath("PraceLamania[" + vm.PraceLamania.IndexOf(dpl) + "].DPL_Wynik"),
    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
    Mode = BindingMode.OneWay,
    Source = vm
});

BindingOperations.SetBinding(tb, TextBlock.TextProperty, multiTbBinding);

当我执行单个值绑定(bind)时,一切都很好,但是在这种情况下,我不知道我在哪里出错。

我可以要求任何建议吗?

最佳答案

该错误在StringFormat中很简单。尝试一下:

multiTbBinding.StringFormat = "{0} + {1}";

如果添加到原始代码中:
multiTbBinding.FallbackValue = "Fallback";

那么您将在Text属性中获得“备用”。

关于c# - 在后面的代码中多重绑定(bind)到TextBlock-我在哪里弄错了?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54037447/

10-15 02:45