Answer the question
In order to leave comments, you need to log in
How to bind an element using RelativeSource in WPF to another element of the same level?
I have a ListBox with the following item template:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="true"></CheckBox>
<Image Width="22"
Height="22"
Margin="5"
Source="/Images/play.png"
>
<Image.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsChecked, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=CheckBox}}" Value="true">
<Setter Property="Image.Source" Value="/Images/pause.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsChecked, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=CheckBox}}" Value="false">
<Setter Property="Image.Source" Value="/Images/play.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<StackPanel>
<TextBlock FontWeight="Bold" Text="{Binding Path=title}"></TextBlock>
<TextBlock Text="{Binding Path=duration}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question