Way of Binding: Linking scrolling

I had to do something to link two scrollviewers together. The use case for this is when you what to compare two things together (like diffing of objects).

To handle this the trick was to have a converter which multiplied -1 to the scrollers.


<ScrollViewer Grid.Column="0" Grid.Row="3" x:Name="leftScroller"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ContentPresenter Content="{Binding SelectedMarketDataOne}"
ContentTemplateSelector="{StaticResource MarketDataTemplateSelector}">
<ContentPresenter.Style>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform X="{Binding ElementName=rightScroller, Path=HorizontalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=-1}" />
<TranslateTransform Y="{Binding ElementName=rightScroller, Path=VerticalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=-1}" />
</TransformGroup>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=tbLink,Path=IsChecked}" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform X="{Binding ElementName=rightScroller, Path=HorizontalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=0}" />
<TranslateTransform Y="{Binding ElementName=rightScroller, Path=VerticalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=0}" />
</TransformGroup>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentPresenter.Style>
</ContentPresenter>
</ScrollViewer>

<ScrollViewer Grid.Column="2" Grid.Row="3" x:Name="rightScroller"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ContentPresenter Content="{Binding SelectedMarketDataTwo}"
ContentTemplateSelector="{StaticResource MarketDataTemplateSelector}">
<ContentPresenter.Style>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform X="{Binding ElementName=leftScroller, Path=HorizontalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=-1}" />
<TranslateTransform Y="{Binding ElementName=leftScroller, Path=VerticalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=-1}" />
</TransformGroup>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=tbLink,Path=IsChecked}" Value="True">
<Setter Property="RenderTransform">
<Setter.Value>
<TransformGroup>
<TranslateTransform X="{Binding ElementName=leftScroller, Path=HorizontalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=0}" />
<TranslateTransform Y="{Binding ElementName=leftScroller, Path=VerticalOffset, Converter={StaticResource MultiplyConverter}, ConverterParameter=0}" />
</TransformGroup>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentPresenter.Style>
</ContentPresenter>
</ScrollViewer>


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s