-1

我有两个网格,我想一次只选择一个选定的项目,即如果 A 和 B 是两个网格,那么如果我从 A 中选择,那么从 B 中选择的项目应该被取消选择,并且应该在同一次单击中选择 A 项目并且相同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;
            }
        }

请帮助我。

4

2 回答 2

0

您应该处理两个网格的单击事件,并且在这些事件中您应该检查活动控制,例如

        if(this.ActiveControl==yourgrid1)
            //yourgrid2.selecteditem=null

我希望它有帮助。

于 2013-07-03T04:30:05.247 回答
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;
                }
            }
        }
于 2013-07-03T04:39:35.167 回答