Binding ComboBox Item with a text property of different DataContext

Posted by Jhelumi786 on Stack Overflow See other posts from Stack Overflow or by Jhelumi786
Published on 2010-06-21T13:37:25Z Indexed on 2011/03/07 16:10 UTC
Read the original article Hit count: 188

Filed under:
|
|

Hi Everyone, I have a comboBox as below. What I want is to bind the selectedItem value to a Text property of a datacontext so that another DataTemplate can show the Image. Please note that the Combobox and Target Image elements are on two different DataTemplates so that's why I need to update the Text Property (ImageName) ofDataContext at backend.

<ComboBox x:Name="cboOverlay" Grid.Row="0" Grid.Column="1" SelectedIndex="0" >
  <ComboBoxItem  Name="BC_OL" IsSelected="True">
       <StackPanel Orientation="Horizontal">
          <Image Source="Images\BC_OL.jpg"  Width="100" Height="25" Canvas.Top="0" Canvas.Left="0" />
        <TextBlock Width="100" VerticalAlignment="Center" TextAlignment="Center"><Bold>Image1</Bold></TextBlock>
       </StackPanel>
  </ComboBoxItem>
  <ComboBoxItem Name="Indian_OL">
      <StackPanel Orientation="Horizontal">
          <Image Source="Images\Indian_OL.jpg"  Width="100" Height="25" Canvas.Top="0" Canvas.Left="0" />
       <TextBlock Width="100" VerticalAlignment="Center" TextAlignment="Center"><Bold>Image2</Bold></TextBlock>
     </StackPanel>
  </ComboBoxItem>
 </ComboBox>
    <Image Source="{Binding Path=Image}" Width="81" Height="25" Canvas.Top="0" Canvas.Left="0" />

© Stack Overflow or respective owner

Related posts about wpf

Related posts about binding