【发布时间】:2013-10-08 07:52:33
【问题描述】:
所以我有一个名为信号图的类,我想在滚动查看器执行任务时对其进行更新。
信号图通过这些依赖属性连接到滚动查看器:
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(导致回调中没有代码,只是一个无用的测试)>
我想这没什么大不了的,但我只是想知道人们会推荐什么。
我想更新一次
【问题讨论】:
标签: c# wpf xaml binding dependency-properties