ZoomIn/ZoomOut
Last post 04-30-2008 4:02 AM by Yi-Lun Luo - MSFT. 11 replies.
Sort Posts:
04-24-2008 6:52 AM
ZoomIn/ZoomOut

Does anyone know of a way that I can take a usercontrol(screen) and shrink it down to a certain size and have all its children resize as well.  I want to be able to take screens and shrink them down and put them in a StackPanel.  This will allow the user to minimize the screen in its current state and recall it to its original size include any data the user typed in.  I have a wrapper control that I use to place different usercontrols in.  So I would always be shrinking down the wrapper control but the children inside the wrapper control will be different and have different sizes.

I tried using a storyboard but that did not work because the controls are different sizes.  So I want to take the original size and shrink everyting down to maybe 150 wide x 100 height.

 Any ideas?  Oh yea I am uysing vb.net but I can read c#

Thanks

completetrader

Joined on 09-17-2007
Posts 117
04-24-2008 7:41 AM
Re: ZoomIn/ZoomOut

You can assign a ScaleTransform to your UserControl.RenderTransform property. All your usercontrol and it's content will be resized.

Thierry Bouquain
Ucaya
http://www.ucaya.com

thierry.bouquain

Joined on 05-06-2007
Nantes, France
Posts 224
04-24-2008 7:44 AM
Re: ZoomIn/ZoomOut

Do you have any sample code.  FOr some reason I just cannot figure out how to do that.  Not enough sleep I guess.

 

Thanks

completetrader

Joined on 09-17-2007
Posts 117
04-24-2008 9:22 AM
Re: ZoomIn/ZoomOut

Here the control will be 4 times smaller.

<UserControl x:Class="SilverlightApplication4.Page"
    xmlns="http://schemas.microsoft.com/client/2007"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="500" Height="500"
             xmlns:local="clr-namespace:SilverlightApplication4;assembly=SilverlightApplication4">
    <UserControl.RenderTransform>
        <ScaleTransform ScaleX="0.25" ScaleY="0.25"/>
    </UserControl.RenderTransform>

    <StackPanel >
        <Button Content="TestButton"/>
        <Image Source="http://labs.ucaya.com/ucaya.png"/>
        <TextBlock Text="ucaya" Foreground="Red"/>
 </StackPanel>
</UserControl>

Thierry Bouquain
Ucaya
http://www.ucaya.com

thierry.bouquain

Joined on 05-06-2007
Nantes, France
Posts 224
04-24-2008 2:35 PM
Re: Re: ZoomIn/ZoomOut

Thanks for the code.  BUt when I apply this to my control it takes a part of the screen and shrinks it down.  I have to do it in the code behind file.  Here is the code:

Dim tt = New ScaleTransform
tt.ScaleX = 0.25
tt.ScaleY = 0.25
tg.Children.Add(tt)
PMScreen.RenderTransform = tg

completetrader

Joined on 09-17-2007
Posts 117
04-28-2008 3:47 AM
Re: Re: Re: ZoomIn/ZoomOut
Hello, you can set RenderTransformOrigin to 0,0 to avoid this issue.

 

shanaolanxing - Please mark the posts as answers if they help and unmark if they don't.

Yi-Lun Luo - MSFT

Joined on 10-29-2007
Posts 1,084
04-28-2008 4:41 AM
Re: ZoomIn/ZoomOut

 I hade the same problem.

I'm not sure is the best way to resolve, anyway I use a grid to change dimension of all object, and all object have fixed witdht and height.

            private void zoom(double scale)
            {
                zoommLevel.RenderTransform = new ScaleTransform(scale, scale, (zoommLevel.ActualWidth / 2), (zoommLevel.ActualHeight / 2));
            }

www.obsidianart.com

obsidianart

Joined on 04-23-2008
sassari - pisa
Posts 6
04-28-2008 4:46 AM
Re: Re: ZoomIn/ZoomOut

Use RenderTransformOrigin to (0,0)....

 

(If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

microsoft_kc

Joined on 03-27-2008
Posts 29
04-28-2008 12:07 PM
Re: Re: ZoomIn/ZoomOut

Well I have my usercontrol set to Auto with and Auto Height so it will resize.  I can get the desired effect of I set a specific height and width but when I do not know how to set it back to Auto when I restore the screen.  This should be easy but it is causing me a lot of trouble.

completetrader

Joined on 09-17-2007
Posts 117
04-28-2008 12:34 PM
Re: Re: Re: ZoomIn/ZoomOut

I use a grid and modify the grid, and i never put it to auto again, I use scaleTransform to zoom, not height or width, and i just have to reset to 1.

fixed width or height is just a trick to don't have strange resize, but i'm not sure you will need to.

Zoommlevel in my code is REALLY a zoomleve, that contains a lot of object inside. 

www.obsidianart.com

obsidianart

Joined on 04-23-2008
sassari - pisa
Posts 6
04-28-2008 2:26 PM
Re: Re: Re: Re: ZoomIn/ZoomOut

It sur would be a lot easier if I could just set it back to Auto width and height.  Does anyone know how to do that in the code behind file?  I just get an error when I try to set the Usercontrol.Widthproperty = "Auto"

completetrader

Joined on 09-17-2007
Posts 117
04-30-2008 4:02 AM
Re: Re: Re: Re: Re: ZoomIn/ZoomOut

You can set it to double.NaN. This is the equivalence to Auto in XAML.

shanaolanxing - Please mark the posts as answers if they help and unmark if they don't.

Yi-Lun Luo - MSFT

Joined on 10-29-2007
Posts 1,084