简体   繁体   中英

Binding error on MultiBinding Converter

As a relative newbie to WPF I'm struggling to see why I am getting binding errors in the following scenario.

I have the following XAML

<TextBlock.Text>
    <MultiBinding Converter="{StaticResource CardinalityConverter}">
        <Binding/>
        <Binding Path="ed.Min" />
        <Binding Path="ed.Max" />
    </MultiBinding>
</TextBlock.Text>

The binding errors I get is as follows

System.Windows.Data Warning: 40 : BindingExpression path error: 'ed' property not found on 'object' ''SDNode' (HashCode=2343823)'. BindingExpression:Path=ed.Min; DataItem='SDNode' (HashCode=2343823); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Warning: 40 : BindingExpression path error: 'ed' property not found on 'object' ''SDNode' (HashCode=2343823)'. BindingExpression:Path=ed.Max; DataItem='SDNode' (HashCode=2343823); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

If I put a breakpoint in the "CardinalityConverter" then the following is seen, you can see value(1) and value(2) are unset.

在此处输入图片说明

If I expand value(0) then the following is seen

在此处输入图片说明

'ed' is clearly seen so why does the binding not recognise this?

A field can't be the source or the target of a Binding , only normal CLR properties or dependency properties can participate in WPF's binding system.

Try setting your bindings to the following:

<Binding Path="ED.Min" />
<Binding Path="ED.Max" />

If I'm not mistaken, judging by the image you provided you already have a public property called ED exposed, so the binding should work with that.

A field looks like this:

public class SomeClass
{
    public string SomeField = "Some Value";
}

While a property looks like this:

public class SomeClass
{
    public string SomeProperty { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM