使用WPF C#时,是否有减少或防止表格闪烁的方法?

时间:2018-08-14 07:37:17

标签: c# wpf wpf-controls wpftoolkit

我遇到了闪烁的问题:

enter image description here

预期:当鼠标悬停在相应单元格上时,将突出显示边框(橙色)。

实际:边界持续闪烁

任何人都可以帮助解决此问题吗?

` private void ShowCellCtrl(FrameworkElement imposeCell)
        {
            const int flipHorz = 0, flipVert = 1, cellRotate = 2, rowRotate = 3, colRotate = 4;

        if (imposeCell as Border == null) return;
        if (CellCtrl.Tag == imposeCell) return;

        var sheet = imposeCell.Parent as Canvas;
        if (sheet == null) return;
        var animTime = 0.2;
        var sheetInfo = sheet.Tag as SheetInfo;

        RemoveCellCtrl();

        CellCtrl.Tag = imposeCell;
        var borderThick = CellCtrl.BorderThickness;
        var borderWidth = (borderThick.Left + borderThick.Right) / 2;
        var borderHeight = (borderThick.Top + borderThick.Bottom) / 2;

        var ctrlGrid = CellCtrl.Child as Grid;
        ctrlGrid.Width = imposeCell.Width - borderWidth;
        ctrlGrid.Height = imposeCell.Height - borderHeight;

        var cellNum = (int)imposeCell.Tag;
        var rectCell = new Rectangle { Width = imposeCell.Width, Height = imposeCell.Height };
        var rectPos = new Point((double)imposeCell.GetValue(Canvas.LeftProperty),
                                (double)imposeCell.GetValue(Canvas.TopProperty));

        if (GridMode == GridEditMode.Column)
            rectPos = GetColumnRect(cellNum, sheetInfo, out rectCell);

        else if (GridMode == GridEditMode.Row)
            rectPos = GetRowRect(cellNum, sheetInfo, out rectCell);

        CellCtrl.Width = rectCell.Width;
        CellCtrl.Height = rectCell.Height;
        CellCtrl.SetValue(Canvas.LeftProperty, rectPos.X);
        CellCtrl.SetValue(Canvas.TopProperty, rectPos.Y);

        if (GridMode == GridEditMode.Cell)
        {
            ctrlGrid.Children[flipHorz].Visibility = Visibility.Visible;
            ctrlGrid.Children[flipVert].Visibility = Visibility.Visible;
            ctrlGrid.Children[cellRotate].Visibility = Visibility.Visible;
            ctrlGrid.Children[rowRotate].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[colRotate].Visibility = Visibility.Collapsed;
            CellCtrl.BorderBrush = new SolidColorBrush(_ctrlBorderColor);
            FadeCtrls(true, animTime, CellCtrl, ctrlGrid.Children[flipHorz], ctrlGrid.Children[flipVert], ctrlGrid.Children[cellRotate]);
        }
        else if (GridMode == GridEditMode.Column)
        {
            ctrlGrid.Children[flipHorz].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[flipVert].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[cellRotate].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[rowRotate].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[colRotate].Visibility = Visibility.Visible;
            CellCtrl.BorderBrush = new SolidColorBrush(_ctrlBorderColor);
            FadeCtrls(true, animTime, CellCtrl, ctrlGrid.Children[colRotate]);
        }
        else if (GridMode == GridEditMode.Row)
        {
            ctrlGrid.Children[flipHorz].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[flipVert].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[cellRotate].Visibility = Visibility.Collapsed;
            ctrlGrid.Children[rowRotate].Visibility = Visibility.Visible;
            ctrlGrid.Children[colRotate].Visibility = Visibility.Collapsed;
            CellCtrl.BorderBrush = new SolidColorBrush(_ctrlBorderColor);
            FadeCtrls(true, animTime, CellCtrl, ctrlGrid.Children[rowRotate]);
        }
        sheet.Children.Add(CellCtrl);
    }`  

注意:添加了我的代码。在工作1或2分钟后,细胞会发出类似的声音。 谢谢。

0 个答案:

没有答案