views:

4295

answers:

4

How can I implement a zoom control to my wpf forms similar to the one avaialble in the visual studio designer?

thanks!

+9  A: 

Put your stuff into a grid, bind the grid's scale render transformation to a slider (slider should have min value of 1):

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="0.867*"/>
            <RowDefinition Height="0.133*"/>
        </Grid.RowDefinitions>
        <Slider x:Name="slider" Grid.Row="1" Minimum="1"/>
        <Grid RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform 
                    ScaleY="{Binding Path=Value, ElementName=slider}" 
                    ScaleX="{Binding Path=Value, ElementName=slider}"/>
                </TransformGroup>
            </Grid.RenderTransform>
            <TextBox Text="TextBox" Height="45.214"
 VerticalAlignment="Top" Margin="194,139,209,0"/>
            <TextBox VerticalAlignment="Bottom" 
Text="TextBox" Margin="194,0,209,118.254" Height="48.96"/>
        </Grid>
    </Grid>
Sergey Aldoukhov
You may want to use `LayoutTransform` for zooming, this will alow any parent `ScrollViewer` controls to show scroll bars correctly.
Brett Ryan
@Brett: Thanks! Your comment answered my related question perfectly!
Beska
+1  A: 

You should have a look at this article by Mitsu Furuta (don't worry about the funny title !). I'm not sure whether it meets your requirements exactly, but it could give you some ideas...

Thomas Levesque
+2  A: 
Palesz
+1  A: 

To get a professional Zoom Control for WPF check out the ZoomPanel.

It is not free, but is very easy to use and has many features - animated zooming and panning, support for ScrollViewer, mouse wheel support, included ZoomController (with move, zoom in, zoom out, rectangle zoom, reset buttons). It also comes with many code samples.

Andrej Benedik