locked
How can I prevent applying ScaleTranform for children controls (From its Parent control) in windows store app in c++ RRS feed

  • Question

  • HI,

    How can I prevent applying ScaleTranform for children controls (From its Parent control) in windows store app in c++

    Wednesday, October 10, 2012 12:34 PM

Answers

  • When you multiply the parent's Scaling factors, divide the child's by the same amount. Depending on what effect you are looking for you may also want to de-scale the child's position:

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Canvas Background="LightBlue" Margin="371,203,358,155"
                    ManipulationMode="Scale"
                    ManipulationDelta="Canvas_ManipulationDelta_1"
                    >
                <Canvas.RenderTransform>
                    <ScaleTransform />
                </Canvas.RenderTransform>
                <Rectangle x:Name="blueRect" Height="100" Width="100" Fill="DarkBlue" Stroke="White" Canvas.Left="270" Canvas.Top="149">
                    <Rectangle.RenderTransform>
                        <ScaleTransform />
                    </Rectangle.RenderTransform>
                </Rectangle>
            </Canvas>
        </Grid>
    void InverseScale::MainPage::Canvas_ManipulationDelta_1(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs^ e)
    {
    	// Scale the canvas per the manipulation
    	UIElement^ canvas = safe_cast<UIElement^>(sender);
    	ScaleTransform^ trans = safe_cast<ScaleTransform^>(canvas->RenderTransform);
    	trans->ScaleX *= e->Delta.Scale;
    	trans->ScaleY *= e->Delta.Scale;
    
    	// Scale the rectangle the other direction
    	ScaleTransform^ trans2 = safe_cast<ScaleTransform^>(blueRect->RenderTransform);
    	trans2->ScaleX /= e->Delta.Scale;
    	trans2->ScaleY /= e->Delta.Scale;
    	
    	// Scale the rectangle's position within the Canvas
    	double x = safe_cast<double>(blueRect->GetValue(Canvas::LeftProperty));
    	double y = safe_cast<double>(blueRect->GetValue(Canvas::TopProperty));
    	blueRect->SetValue(Canvas::LeftProperty,x / e->Delta.Scale);
    	blueRect->SetValue(Canvas::TopProperty,y / e->Delta.Scale);
    }

    --Rob
    • Marked as answer by Bilaal John S Wednesday, October 17, 2012 4:07 AM
    Wednesday, October 17, 2012 1:50 AM
    Moderator

All replies

  • Do you mean that you want to scale a container but leave the children unscaled?

    There isn't an automatic way to do this, but you could scale the parent up and apply an inverse scaling to the children so they end up their original size.

    --Rob

    Wednesday, October 10, 2012 7:56 PM
    Moderator
  • hi Rob,

    please provide me example for reverse scaling.

    regards,

    sarath s

    Thursday, October 11, 2012 6:08 AM
  • Revers scaling in windows store app
    Monday, October 15, 2012 12:21 PM
  • When you multiply the parent's Scaling factors, divide the child's by the same amount. Depending on what effect you are looking for you may also want to de-scale the child's position:

        <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
            <Canvas Background="LightBlue" Margin="371,203,358,155"
                    ManipulationMode="Scale"
                    ManipulationDelta="Canvas_ManipulationDelta_1"
                    >
                <Canvas.RenderTransform>
                    <ScaleTransform />
                </Canvas.RenderTransform>
                <Rectangle x:Name="blueRect" Height="100" Width="100" Fill="DarkBlue" Stroke="White" Canvas.Left="270" Canvas.Top="149">
                    <Rectangle.RenderTransform>
                        <ScaleTransform />
                    </Rectangle.RenderTransform>
                </Rectangle>
            </Canvas>
        </Grid>
    void InverseScale::MainPage::Canvas_ManipulationDelta_1(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs^ e)
    {
    	// Scale the canvas per the manipulation
    	UIElement^ canvas = safe_cast<UIElement^>(sender);
    	ScaleTransform^ trans = safe_cast<ScaleTransform^>(canvas->RenderTransform);
    	trans->ScaleX *= e->Delta.Scale;
    	trans->ScaleY *= e->Delta.Scale;
    
    	// Scale the rectangle the other direction
    	ScaleTransform^ trans2 = safe_cast<ScaleTransform^>(blueRect->RenderTransform);
    	trans2->ScaleX /= e->Delta.Scale;
    	trans2->ScaleY /= e->Delta.Scale;
    	
    	// Scale the rectangle's position within the Canvas
    	double x = safe_cast<double>(blueRect->GetValue(Canvas::LeftProperty));
    	double y = safe_cast<double>(blueRect->GetValue(Canvas::TopProperty));
    	blueRect->SetValue(Canvas::LeftProperty,x / e->Delta.Scale);
    	blueRect->SetValue(Canvas::TopProperty,y / e->Delta.Scale);
    }

    --Rob
    • Marked as answer by Bilaal John S Wednesday, October 17, 2012 4:07 AM
    Wednesday, October 17, 2012 1:50 AM
    Moderator
  • hi rob,

                       thnkz...

    Regards,

    Sarath s

    Wednesday, October 17, 2012 4:35 AM