WPF派生的Shape触发重绘属性更改

时间:2014-07-30 14:44:34

标签: c# wpf shape redraw

我有一个循环进度条,我已将其实现为从Shape派生的类。我为我需要绑定的所有属性添加了DependencyProperties。属性Value表示进度。我凌驾于DefiningGeometry

现在,我希望获得进度条以反映Value更改时的更改。我目前的做法是在PropertyChangedCallback DepencencyProperties上注册shape.InvalidateVisual()

这样可以正常工作,除非我的进度条上有TooltipTimer增加ValueTooltip 闪烁一次。

更新形状的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

事实证明,闪烁是由扩展的ObservableCollection触发的,这会产生NotifyCollectionChangedAction.Reset事件,触发重新绘制ItemsControl中包含Shapes的所有项目}。

关注How to properly refresh a custom shape in WPF?后,我将DepependecyProperty改进为:

    public static readonly DependencyProperty StartProperty =
        DependencyProperty.Register(
            "Start",
            typeof(double),
            typeof(CircleSegment),
            new FrameworkPropertyMetadata(
                0.0,
                FrameworkPropertyMetadataOptions.AffectsRender));

    /// <summary>
    /// Start of the Segment. 0 is top (12 o'clock), 0.25 is right (3 o'clock), 0.25 is bottom (6 o'clock), 0.75 is left (9 o'clock).
    /// Painting is always Clockwise from Start to End.
    /// </summary>
    [TypeConverter(typeof(LengthConverter))]
    public double Start
    {
        get { return (double)GetValue(StartProperty); }
        set { SetValue(StartProperty, value); }
    }