我的列表框:
<ListBox x:Name="listBox" Grid.Row="2" FontSize="26" SelectionChanged="listBox_SelectionChanged" ItemsSource="{Binding SelectedSubGenre.PhotoCollection}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="BurlyWood" BorderThickness="1,1,1,1" Margin="0,0,12,24">
<StackPanel Orientation="Vertical" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
<Image Source="{Binding Path}" Height="200" HorizontalAlignment="Left" Width="200" Margin="12,12,12,12"/>
<Button Foreground="yellow" Click="Button_Click" Height="150" Width="150" Content="add"/>
</StackPanel>
<TextBlock Text="{Binding Name}" Margin="12,0,0,0"/>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
单击按钮时,我想对按钮的相邻图像执行某些操作,如何在代码中指定此特定图像?如何根据不同的按钮点击获取相邻图像
答案 0 :(得分:2)
在按钮单击回调中,执行以下操作:
var btn = sender as Button;
var dc = btn.DataContext as YourDataObject;
dc.Path = "/path/to/new/image.jpg";
您可能必须使用值转换器将字符串中的路径更改为BitmapImage
。