Note that there are some explanatory texts on larger screens.

plurals
  1. POSelective zoom and pan in WPF
    primarykey
    data
    text
    <p>I need to implement zooming and panning around X-axis in my bus schedule graph viewer (and, possibly, editor) written in C#/WPF. I could use simple transforms, but note that when the distance between points gets larger, the size of the points remains the same. Also, the names of the bus stations should remain on the fixed positions on the left, no matter how I pan the graph:</p> <p><img src="https://i.stack.imgur.com/nCUGb.png" alt="before zoom"> <img src="https://i.stack.imgur.com/x2QFc.png" alt="after zoom"></p> <p>With the current approach, all the visuals are rendered on a single ItemsControl with Canvas as an ItemsPanel and several DataTemplates, one for each type of shape (point, segment, time split line, station line). So, every shape is binded to according ViewModel, which has PosX and PosY properties, provided to Canvas:</p> <pre class="lang-cs prettyprint-override"><code>&lt;ItemsControl.ItemContainerStyle&gt; &lt;Style&gt; &lt;Setter Property="Canvas.Left" Value="{Binding Path=PosX, UpdateSourceTrigger=PropertyChanged}" /&gt; &lt;Setter Property="Canvas.Top" Value="{Binding Path=PosY, UpdateSourceTrigger=PropertyChanged}" /&gt; &lt;/Style&gt; &lt;/ItemsControl.ItemContainerStyle&gt; </code></pre> <p>When I need to pan or zoom, I call OnPropertyChanged("PosX") for viewmodel of each shape. Then the property is recalculated with new values of PanX and ZoomX properties of entire graph:</p> <pre class="lang-cs prettyprint-override"><code>public double PosX { get { return _scheduleGraphViewModel.ZoomX * _shedulePointModel.PlanTime + _scheduleGraphViewModel.PanX; } } </code></pre> <p>The problem is that this works much slower than I was hoping. On 1000+ points it is almost unusable. Profiler tells me that the bottleneck is inside OnPropertyChanged method.</p> <p>I assume that the entire approach is wrong, but I cannot find or think out better solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload