【问题标题】:Error in DataGrid random behavior when scrolling in Silverlight 4.0在 Silverlight 4.0 中滚动时 DataGrid 随机行为出错
【发布时间】:2011-06-01 14:53:12
【问题描述】:

我有一个数据网格,它的行根据某些条件进行着色。我的数据网格有一个垂直滚动条。如果用户滚动数据网格,彩色行的索引 r 会发生变化。例如:如果 2如果用户向下滚动并向上滚动,则行是彩色的,彩色行的索引变得混乱......

这里是代码......

 dggeneralconfiguration.LoadingRow += new EventHandler<DataGridRowEventArgs>(grid1_LoadingRow);
                dggeneralconfiguration.UnloadingRow += new EventHandler<DataGridRowEventArgs>(grid1_UnloadingRow);
void grid1_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid;

            if (c.Status == false)
            {
                if (e.Row != null)
                {
                    e.Row.Background = new SolidColorBrush(Colors.Red);
                    //e.Row.Background = new SolidColorBrush(Colors.Transparent);
                }
            }
        }
        void grid1_UnloadingRow(object sender, DataGridRowEventArgs e)
        {
            ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid;

            if (c.Status == false)
            {
                if (e.Row != null)
                {
                    e.Row.Background = new SolidColorBrush(Colors.Red);
                    //e.Row.Background = new SolidColorBrush(Colors.Transparent);
                }
            }
        }

【问题讨论】:

    标签: silverlight-4.0 datagrid


    【解决方案1】:

    迟到总比没有好。 ;-) 。我也有类似的问题..尝试在卸载行事件时将行背景分配给 null。

        private void dg_UnloadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Background = null;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多