Dax Pandhi's nAESTHETIC Dax Pandhi's nAESTHETIC Dax Pandhi's nAESTHETIC Subscribe to this Blog's RSS feed Subscribe to my DeviantArt RSS feed

Popular art from my DeviantArt account:


  Monday, February 13, 2006


XAML/WPF Experiment: Zoom Functionality

I mentioned in my post about PixelSpread that a LOT of code was replaced by using the simple features of WPF. Here's how it was done. This example illustrates the concept, but with different controls.

On our blank XAML Scene file we have a Grid object and a Slider. The grid is called grdMain and the slider is ingeniusly named Slider. To make this realistically work, we need the Grid to be in some sort of container to mask the view, but that's beyond the scope of this example. The slider's VALUE will provide the zoom factor. 0 being nothing and 10 (1000%) being the highest. Here's code:

<Grid Width="Auto" Height="Auto" Background="#FF000000" x:Name="grdMain" MinWidth="0" RenderTransformOrigin="0.5,0.5" Margin="13,16,10,46" MinHeight="0">
  <Grid.RenderTransform>
    <ScaleTransform CenterX="0" CenterY="0">
        <ScaleTransform.ScaleX>
            <Binding Mode="Default" Path="Value" ElementName="Slider"/>
        </ScaleTransform.ScaleX>
        <ScaleTransform.ScaleY>
            <Binding Mode="Default" Path="Value" ElementName="Slider"/>
        </ScaleTransform.ScaleY>
    </ScaleTransform>
  </Grid.RenderTransform>

 </Grid>

 <Slider Width="132" Height="21" x:Name="Slider" RenderTransformOrigin="0.5,0.5" Margin="0,0,42,14" HorizontalAlignment="Right" VerticalAlignment="Bottom" Value="1"/>

The code is pretty straight forward. We have databound the Grid.RenderTranform.ScaleTransform.ScaleX (and Y) properties to the Slider's VALUE property. You can also use RotateTransform or other transforms as well.

To find out more about the ScaleTransform object, see this link in the WinFX Documentation. For other transforms and the Transform object itself, see this link.

The documentation notes that the RenderTransform object does only TEMPORARY transforms. That is, it does not regenerate layout size, etc. But you can simply use such binding to other "tangible" objects for storage.









4/7/2007 5:06:23 AM (India Standard Time, UTC+05:30)
Order cheap tramadol online.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Copyright � 2005-2007 Dax Pandhi. All rights reserved.
designed by nukeation
Sign In