none
ScaleTransform

    Question

  • Hai,
             I struck up with this problem, my sample code goes up this way.

    <Window x:Class="ButtonTransform.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
        <Grid>
            <Button Height="100" Width="100"> TestApp
                <Button.LayoutTransform>
                    <ScaleTransform ScaleX="2" ScaleY="2"></ScaleTransform>
                </Button.LayoutTransform>
            </Button>
        </Grid>
    </Window>


    Issue i am facing is:
              Wen i do this transform my button gets transform well, but the content "TestApp" also gets transformed up, i don't want my content to be transformed.if i transform any other controls with children ,childrens also gets transformed along with control,
    so, how do i do this, if there is any other way to do this, do suggest me!

    Thanks and Keep Smiling .


    Black panther
    Monday, November 10, 2008 1:31 PM

Answers

  • If you scale down the content when you scale up the button the content should stay the same size.
    Here is an example:

    <Button Height="100" Width="100">TestApp  
                <Button.Template> 
                    <ControlTemplate TargetType="{x:Type Button}">  
                        <theme:ButtonChrome Name="Chrome" 
                                            Background="{TemplateBinding Background}" 
                                            BorderBrush="{TemplateBinding BorderBrush}" 
                                            RenderDefaulted="{TemplateBinding Button.IsDefaulted}" 
                                            RenderMouseOver="{TemplateBinding IsMouseOver}" 
                                            RenderPressed="{TemplateBinding IsPressed}" 
                                            SnapsToDevicePixels="true">  
                            <ContentPresenter Margin="{TemplateBinding Padding}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              RecognizesAccessKey="True" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">  
                                <ContentPresenter.LayoutTransform> 
                                    <ScaleTransform ScaleX="0.5" ScaleY="0.5" /> 
                                </ContentPresenter.LayoutTransform> 
                            </ContentPresenter> 
                        </theme:ButtonChrome> 
                    </ControlTemplate> 
                </Button.Template> 
                <Button.LayoutTransform> 
                    <ScaleTransform ScaleX="2" ScaleY="2" /> 
                </Button.LayoutTransform> 
            </Button> 

    In your project you will need to add a reference to PresentationFramework.Aero, and also add this xmlns namespace to your window 

    xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"

    Hope this helps,
    Alex

    • Edited by aSchimp Monday, November 10, 2008 10:44 PM
    • Marked as answer by Marco Zhou Thursday, November 13, 2008 7:33 AM
    Monday, November 10, 2008 9:46 PM

All replies

  • If you scale down the content when you scale up the button the content should stay the same size.
    Here is an example:

    <Button Height="100" Width="100">TestApp  
                <Button.Template> 
                    <ControlTemplate TargetType="{x:Type Button}">  
                        <theme:ButtonChrome Name="Chrome" 
                                            Background="{TemplateBinding Background}" 
                                            BorderBrush="{TemplateBinding BorderBrush}" 
                                            RenderDefaulted="{TemplateBinding Button.IsDefaulted}" 
                                            RenderMouseOver="{TemplateBinding IsMouseOver}" 
                                            RenderPressed="{TemplateBinding IsPressed}" 
                                            SnapsToDevicePixels="true">  
                            <ContentPresenter Margin="{TemplateBinding Padding}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              RecognizesAccessKey="True" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">  
                                <ContentPresenter.LayoutTransform> 
                                    <ScaleTransform ScaleX="0.5" ScaleY="0.5" /> 
                                </ContentPresenter.LayoutTransform> 
                            </ContentPresenter> 
                        </theme:ButtonChrome> 
                    </ControlTemplate> 
                </Button.Template> 
                <Button.LayoutTransform> 
                    <ScaleTransform ScaleX="2" ScaleY="2" /> 
                </Button.LayoutTransform> 
            </Button> 

    In your project you will need to add a reference to PresentationFramework.Aero, and also add this xmlns namespace to your window 

    xmlns:theme="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"

    Hope this helps,
    Alex

    • Edited by aSchimp Monday, November 10, 2008 10:44 PM
    • Marked as answer by Marco Zhou Thursday, November 13, 2008 7:33 AM
    Monday, November 10, 2008 9:46 PM
  • Hi,
          Exact Solution, thanks u so much


    Black panther
    Thursday, November 13, 2008 9:38 AM