【问题标题】:Silverlight Datagrid Refresh Data with SelectionChanged BindingSilverlight Datagrid 使用 SelectionChanged 绑定刷新数据
【发布时间】:2010-11-22 19:58:35
【问题描述】:

我正在构建一个使用 Silverlight 的问题跟踪系统。我使用 DataGrids 来显示问题列表,将选定索引设置为 -1,这样就不会显示任何行被选中,然后使用选择更改事件来弹出特定选定问题的问题详细信息窗口。

当我尝试通过将 DataGrid 重新绑定到其 ItemsSource 来刷新 DataGrid 时,我禁用了 SelectionChanged 事件,将 DataGrid 重新绑定到其 ItemsSource,将 SelectedIndex 设置为 -1,然后再次启用 SelectionChanged 事件。但是,无论我离开重新启用 SelectionChanged 事件多晚(甚至在 DataGrid_Loaded 事件之后),都​​会触发一个 SelectionChanged 事件并弹出问题详细信息窗口。

有没有更好的方法来刷新 DataGrid 中不会导致 SelectedIndex 更改的数据?如果不是,有没有办法判断哪些事件是由程序索引更改而不是人为交互引起的?

(也有待讨论,这是工作的最佳控制吗?我需要每行显示多个字段,例如问题标题、分配的用户、用户请求的用户、状态等)

提前致谢。

【问题讨论】:

    标签: silverlight events datagrid


    【解决方案1】:

    我过去在 comctl32 ListView 控件的选择事件中遇到过类似的问题:编程选择导致选择更改事件被引发。

    我对这个问题的解决方法是有一个每个网格/列表计数器变量,让事件处理程序知道它是否应该关心选择事件。代码如下:

    int issueList_ProgrammaticEventCount_Selection = 0;
    
    void refreshIssueList()
    {
        ++issueList_ProgrammaticEventCount_Selection;
        issueList.ItemsSource = ...;
    }
    
    void issueList_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (issueList_ProgrammaticEventCount_Selection > 0)
        {
            --issueList_ProgrammaticEventCount_Selection;
            return;
        }
    
        showIssueDetails();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      相关资源
      最近更新 更多