我有两个网格,我想一次只选择一个选定的项目,即如果A和B是两个网格,那么如果我从A中选择,则应该取消选择B中的所选项目,并且应该在同一个单击中选择一个项目和B一样。
这些是我的网格,我绑定了相同的选择事件处理程序。
CurrentServiceGridView.SelectionChanged +=CurrentServiceGridView_SelectionChanged;
AllServicesGridView.SelectionChanged += CurrentServiceGridView_SelectionChanged;
这就是我处理事情的方式。
private void CurrentServiceGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (((Windows.UI.Xaml.Controls.ListViewBase)(sender)).Name == CurrentServiceGridView.Name)
{
AllServicesGridView.SelectedItem = null;
}
else
{
CurrentServiceGridView.SelectedItem = null;
}
}
请帮帮我。
答案 0 :(得分:0)
您应该处理两个网格的点击事件,并且在这些事件中您应该检查activecontrol,例如
if(this.ActiveControl==yourgrid1)
//yourgrid2.selecteditem=null
我希望它有所帮助。
答案 1 :(得分:0)
我这样做了
private void CurrentServiceGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (((Windows.UI.Xaml.Controls.ListViewBase)(sender)).Name == CurrentServiceGridView.Name)
{
if (AllServicesGridView.SelectedItem != null)
{
AllServicesGridView.SelectionChanged -= CurrentServiceGridView_SelectionChanged;
AllServicesGridView.SelectedItem = null;
AllServicesGridView.SelectionChanged += CurrentServiceGridView_SelectionChanged;
}
}
else
{
if (CurrentServiceGridView.SelectedItem != null)
{
CurrentServiceGridView.SelectionChanged -= CurrentServiceGridView_SelectionChanged;
CurrentServiceGridView.SelectedItem = null;
CurrentServiceGridView.SelectionChanged += CurrentServiceGridView_SelectionChanged;
}
}
}