Reputation: 3409
So I have a class called signal graph that I want to update when scrollviewer performs a task.
The signal graph is connected to the scrollviewer by these dependency properties:
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));
However, I don't want to just use a dependency property callback on each of the three properties because all 3 of those properties might change on zoom, which would then result in redrawing the signalgraph way too many times.
Normally I think I would just register all the signalgraphs onto a ZoomEvent, but the signal graphs don't have access to the scrollviewer directly. I figure that in WPF it would be more natural to connect them using properties somehow.
I can just make a property bool NeedsToRedraw on the scrollviewer that I only set to true when the zoom has taken place. Then I can bind the signalgraphs to that property and have a propertychangedcallback that calls the redraw function. However, if i reset the bool to false, it will end up calling the propertychangedcallback one more time even though I don't really need to be calling that function.
will this be inefficient? I feel like in some ways events would be cleaner, since I wouldn't be having the propertychangedcallback first get called when I set the value to true (resulting in a redraw) and then again when I set the value back to false (resulting in no code in the callback, just a useless test)>
I guess it's not a huge deal, but I am just wondering what people would recommend.
Instead I want to update once
Upvotes: 1
Views: 127
Reputation: 102753
Using "NeedsToRedraw" would seemingly work fine, and the superfluous property-changed callback is not likely to cause a performance bottleneck. However, maybe one of these is a better alternative:
ZoomProperties
or whatever. (Of course, however, this would also require changes to the consumer class.)Upvotes: 1