Windows phone 7 在列表框中一次选择一个按钮(背景色)

Windows phone 7 在列表框中一次选择一个按钮(背景色),windows-phone-7,Windows Phone 7,因此,我想在列表框中将当前选中的按钮设置为绿色背景,而所有未选中的按钮应保持黑色。我怎样才能做到这一点。查看下面的示例代码。。但是我不能让它工作 foreach(Button btn in ListBox.Items) btn.Background = new SolidColorBrush(Colors.Black); Button clickedButton = sender as Button; clickedButton.Background = new SolidColorBrush(

因此,我想在列表框中将当前选中的按钮设置为绿色背景,而所有未选中的按钮应保持黑色。我怎样才能做到这一点。查看下面的示例代码。。但是我不能让它工作

foreach(Button btn in ListBox.Items)
btn.Background = new SolidColorBrush(Colors.Black);
Button clickedButton = sender as Button;
clickedButton.Background = new SolidColorBrush(Colors.Green);
如果您希望这样做(无需绑定和转换器),请选择: (我还假设listbox项中只有一个按钮)

for(int i=0;i
发布您的ItemTemplate或您正在填充按钮的w/e。您需要列表框中的按钮吗?您可以使用VisualStates执行此行为。
for (int i = 0; i < ListBox.Items.Count; i++)
{
    Button currentButton = ListBox.Items[i] as Button;
    if(currentButton != null)
    {
        if (i == ListBox.SelectedIndex)  
            currentButton.Background = new SolidColorBrush(Colors.Green);

        else 
            currentButton.Background = new SolidColorBrush(Colors.Black);
    }
}