我正在使用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;
}
}
但是我需要使用bind方法,怎么做呢?