C# WPF如何使用属性重新绘制另一个元素?
所以我有一个名为signalgraph的类,我想在scrollviewer执行任务时更新它 信号图通过以下依赖属性连接到scrollviewer:C# WPF如何使用属性重新绘制另一个元素?,c#,wpf,xaml,binding,dependency-properties,C#,Wpf,Xaml,Binding,Dependency Properties,所以我有一个名为signalgraph的类,我想在scrollviewer执行任务时更新它 信号图通过以下依赖属性连接到scrollviewer: public double MinimumXInDIPs { get { return (double)GetValue(MinimumXInDIPsProperty); } set { SetValue(MinimumXInDIPsProperty, value); }
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上,但信号图不能直接访问scrollviewer。我认为在WPF中,以某种方式使用属性连接它们会更自然
我可以在scrollviewer上创建一个属性bool NeedsToRedraw,只有在进行缩放时才将该属性设置为true。然后我可以将信号图绑定到该属性,并拥有一个调用redraw函数的propertychangedcallback。但是,如果我将bool重置为false,它将再次调用propertychangedcallback,即使我实际上不需要调用该函数
这会是低效的吗?我觉得在某些方面事件会更干净,因为当我将值设置为true(导致重新绘制)时,不会首先调用propertychangedcallback,然后当我将值设置为false时(导致回调中没有代码,只是一个无用的测试)>
我想这没什么大不了的,但我只是想知道人们会推荐什么
相反,我希望使用“NeedsToRedraw”更新一次,这样似乎可以正常工作,而且多余的属性更改回调不太可能导致性能瓶颈。然而,也许其中一个是更好的选择:
zoomproperty
或其他任何东西中。(当然,这也需要更改消费者类别。)zoomproperty
或其他任何东西中。(当然,这也需要更改消费者类别。)