Cornel Marian
Cornel Marian

Reputation: 2503

How to Bind the Image Source according the selected item?

How to Bind the Image Source according to the selected item from a listbox that contains items with a property Image?

<Button Name="btn">  
<Button.Header>      
   <StackPanel>      
     <Image name="img">
   <StackPanel>
</Button.Header>
</Button>

Upvotes: 1

Views: 1089

Answers (2)

user2862419
user2862419

Reputation:

Set the Binding like this:

<Image name="img" Source="{Binding SelectedItem.Image, ElementName=myListBox}" />

Upvotes: 0

Jehof
Jehof

Reputation: 35544

With the information you have provided i would do it as follows

<Button Name="btn">  
  <Button.Header>      
   <StackPanel>      
     <Image name="img" Source="{Binding SelectedItem.Image, ElementName=myListBox}" />
   <StackPanel>
  </Button.Header>
</Button>

<ListBox x:Name="myListBox">

</ListBox>

Upvotes: 4

Related Questions