views:

22

answers:

1

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=StatusChoices, 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.

+1  A: 

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

<TextBlock Text="{Binding Path=.,Converter={StaticResource StatusToTextConverter}}"/>
wpfwannabe
That works (and I had never seen that syntax before, very cool)! But it turns out I don't actually need the Path=. in there. In a fit of brilliance, I accidentally deleted the StatusChoices property in my view model. It was a fail on my part, but at least I learned something from your answer, thanks!
unforgiven3
{Binding} and {Binding Path=.} are pretty much equivalent but I have encountered several circumstances where the other syntax must be used (with some additional binding properties of course).
wpfwannabe
yeah, sounds like one of those good ole WPF gotchas :-)
unforgiven3