Tuesday, September 25, 2007

Implementing Microsoft Office 2007 style zooming in WPF

This is a small code snippet which describes about implementing zooming action which is there in most of the components (MS Word 2007 etc) of Office 2007 package.

Basic idea is to put our content in a container and apply scale transform through LayoutTransform based on a slider value.

<Window x:Class="UntitledProject3.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="UntitledProject3" Height="300" Width="300"
>
<StackPanel>
<ScrollViewer Height="100" x:Name="scrl" HorizontalScrollBarVisibility="Auto" Background="{x:Null}" >
<TextBlock Height="19" Margin="0,0,0,0" x:Name="label1" Text ="This is our content">
<TextBlock.LayoutTransform>
<TransformGroup>
<ScaleTransform ScaleX="{Binding Path=Value, ElementName=Slider, Mode=Default}"
ScaleY="{Binding Path=Value, ElementName=Slider, Mode=Default}"/>
</TransformGroup>
</TextBlock.LayoutTransform>
</TextBlock>
</ScrollViewer>
<Slider Value="1" Minimum="1" Maximum="10" x:Name="Slider" />
</StackPanel>
</Window>

No comments:

Post a Comment