开发者

ValueConverter not invoked in DataTemplate binding

开发者 https://www.devze.com 2022-12-28 03:50 出处:网络
I have a ComboBox that uses a DataTemplate. The DataTemplate contains a binding which uses an IValueConverter to convert an enumerated value into a string. The problem is that the value converter is n

I have a ComboBox that uses a DataTemplate. The DataTemplate contains a binding which uses an IValueConverter to convert an enumerated value into a string. The problem is that the value converter is never invoked. If I put a breakpoint in StatusToTextConverter.Convert(), it never is hit.

This is my XAML:

    <ComboBox ItemsSource="{Binding Path=Statu开发者_Go百科sChoices, Mode=OneWay}">
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Converter={StaticResource StatusToTextConverter}}"/>
            </DataTemplate>
        </ComboBox.ItemTemplate>
    </ComboBox>

I thought this is how one implicitly binds to the value a DataTemplate is presenting. Am I wrong?

Edit: For context: I intend to display an Image in the DataTemplate alongside that TextBox. If I can't get the TextBox binding to work, then I don't think the Image will work, either.


In some circumstances you must explicitly supply a Path for a Binding. Try this instead:

<TextBlock Text="{Binding Path=.,Converter={StaticResource StatusToTextConverter}}"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消