0

私のリストボックス:

   <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>

ボタンがクリックされたときに、ボタンの隣の画像で何かをしたいのですが、コードでこの特定の画像を指定するにはどうすればよいですか? さまざまなボタンのクリックに基づいて隣接する画像を取得するにはどうすればよいですか

4

1 に答える 1

2

ボタン クリック コールバックで、次の操作を行います。

var btn = sender as Button;
var dc = btn.DataContext as YourDataObject;
dc.Path = "/path/to/new/image.jpg";

値コンバーターを使用して、パスを文字列からBitmapImage.

于 2012-06-05T23:52:24.103 に答える