を使用しておりListBox
、 をクリックしたときに背景ウィンドウの色を変更したいのですがListBoxItem
、メソッドは機能していますが、バインディングで同じことをしたいです。
<ListBox Grid.Column="1" Grid.Row="3" Grid.RowSpan="2" Margin="10,20,30,10" Name="listBox1" SelectionChanged="listBox1_SelectionChanged_1">
<ListBoxItem Content="Blue" Name="lst" />
<ListBoxItem Content="Green" Name="lst1" />
<ListBoxItem Content="Yellow" Name="lst2"/>
<ListBoxItem Content="Transparent" Name="lst3"/>
</ListBox>
私は次の方法を使用しています:
private void listBox1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
if(listBox1.SelectedIndex.ToString() == "0")
{
win.Background = Brushes.Blue;
}
else if (listBox1.SelectedIndex.ToString() == "1")
{
win.Background = Brushes.Green;
}
else if (listBox1.SelectedIndex.ToString() == "2")
{
win.Background = Brushes.Yellow;
}
else
{
win.Background = Brushes.Transparent;
}
}
しかし、バインド メソッドを使用する必要があります。