所以我有一个叫做信号图的类,我想在滚动查看器执行任务时更新它。
信号图通过这些依赖项财产连接到滚动查看器:
public double MinimumXInDIPs
{
get { return (double)GetValue(MinimumXInDIPsProperty); }
set
{
SetValue(MinimumXInDIPsProperty, value);
}
}
public static readonly DependencyProperty MinimumXInDIPsProperty =
DependencyProperty.Register("MinimumXInDIPs",
typeof(double), typeof(SignalGraph),
new FrameworkPropertyMetadata(new double()));
public double ViewportWidth
{
get { return (double)GetValue(ViewportWidthProperty); }
set
{
SetValue(ViewportWidthProperty, value);
}
}
public static readonly DependencyProperty ViewportWidthProperty =
DependencyProperty.Register("ViewportWidth",
typeof(double), typeof(SignalGraph),
new FrameworkPropertyMetadata(new double()));
public int UnitsOfTimePerAxisDivision
{
get { return (int)GetValue(UnitsOfTimePerAxisDivisionProperty); }
set
{
SetValue(UnitsOfTimePerAxisDivisionProperty, value);
}
}
public static readonly DependencyProperty UnitsOfTimePerAxisDivisionProperty =
DependencyProperty.Register("UnitsOfTimePerAxisDivision",
typeof(int), typeof(SignalGraph),
new FrameworkPropertyMetadata(1));
然而,我不想对三个财产中的每一个都使用依赖属性回调,因为所有这三个财产都可能在缩放时更改,这将导致信号图重绘次数过多。
通常,我认为我只会将所有信号图注册到ZoomEvent上,但信号图不能直接访问滚动查看器。我认为在WPF中,以某种方式使用财产连接它们会更自然。
我可以在滚动查看器上创建一个属性bool NeedsToRedraw,只有在缩放发生时才会将其设置为true。然后,我可以将信号图绑定到该属性,并拥有一个调用重绘函数的propertychangedcallback。然而,如果我将bool重置为false,它最终会再次调用propertychangedcallback,即使我真的不需要调用该函数。
这会不会效率低下?我觉得在某些方面,事件会更干净,因为当我将值设置为true(导致重绘)时,不会首先调用propertychangedcallback,然后当我将该值设置回false(导致回调中没有代码,只是一个无用的测试)>
我想这不是什么大不了的事,但我只是想知道人们会推荐什么。
相反,我想更新一次