Eduardo Brites
Eduardo Brites

Reputation: 4766

How to use converters without binding paths?

I have a Combobox whose ItemsSource is an ObservableCollection of int values. My combobox itemtemplate consists on an image and a textblock which content is given by 2 converters.

How can I set this 2 bindings? The following code does not compile:

<ComboBox.ItemTemplate>
     <DataTemplate>
          <StackPanel Orientation="Horizontal">
               <Image Source="{Binding, Converter={StaticResource IntToImageConverter}}" Stretch="None" />
               <TextBlock Text="{Binding, Converter={StaticResource IntToStringConverter}}" />
          </StackPanel>
     </DataTemplate>
</ComboBox.ItemTemplate>

Upvotes: 19

Views: 7753

Answers (1)

CodeNaked
CodeNaked

Reputation: 41393

You need to remove the , so:

<ComboBox.ItemTemplate>
     <DataTemplate>
          <StackPanel Orientation="Horizontal">
               <Image Source="{Binding Converter={StaticResource IntToImageConverter}}" Stretch="None" />
               <TextBlock Text="{Binding Converter={StaticResource IntToStringConverter}}" />
          </StackPanel>
     </DataTemplate>
</ComboBox.ItemTemplate>

Upvotes: 30

Related Questions