Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Applying a centered ScaleTransform via a Style

 
 
Old 01-31-2006   #1 (permalink)
Pascal Bourque


 
 

Applying a centered ScaleTransform via a Style

Hi,

I would like to apply a ScaleTransform to a control via a Style. This is
easy enough:

<Setter Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="1.25"
ScaleY="1.25" />
</Setter.Value>
</Setter>

But I would like this ScaleTransform to be centered on the control. I
know the CenterX and CenterY properties exist for this purpose, but the
problem is that their value is dynamic (Control.Width/2,
Control.Height/2) and being in a Style declaration I do not know up
front the Width/Height of the control being styled.

Is there a way to specify an expression such as Width/2 declaratively in
XAML?

Thanks!

Pascal

My System SpecsSystem Spec
Old 01-31-2006   #2 (permalink)
Michael Latta


 
 

Re: Applying a centered ScaleTransform via a Style

There is no way to place an expression as an attribute value, and I do not
believe binding will solve this either, although you might be able to bind
the CenterX and CenterY properties to the control on which it is applied.
If that worked you could then create attached properties that are really
derived values using the expression you suggest. Probably an easier
approach would be to create a sub-type of ScaleTransform that computes
CenterX and CenterY dynamically.

Michael
Microsoft MVP (C# / WPF)

"Pascal Bourque" <bourquep@xceedsoft.com> wrote in message
news:upe58hrIGHA.3364@tk2msftngp13.phx.gbl...
> Hi,
>
> I would like to apply a ScaleTransform to a control via a Style. This is
> easy enough:
>
> <Setter Property="RenderTransform">
> <Setter.Value>
> <ScaleTransform ScaleX="1.25"
> ScaleY="1.25" />
> </Setter.Value>
> </Setter>
>
> But I would like this ScaleTransform to be centered on the control. I know
> the CenterX and CenterY properties exist for this purpose, but the problem
> is that their value is dynamic (Control.Width/2, Control.Height/2) and
> being in a Style declaration I do not know up front the Width/Height of
> the control being styled.
>
> Is there a way to specify an expression such as Width/2 declaratively in
> XAML?
>
> Thanks!
>
> Pascal



My System SpecsSystem Spec
Old 01-31-2006   #3 (permalink)
Pascal Bourque


 
 

Re: Applying a centered ScaleTransform via a Style

Thanks for the suggestions, Michael! I will try deriving form
ScaleTransform and post the results here!

Pascal

Michael Latta wrote:
> There is no way to place an expression as an attribute value, and I do not
> believe binding will solve this either, although you might be able to bind
> the CenterX and CenterY properties to the control on which it is applied.
> If that worked you could then create attached properties that are really
> derived values using the expression you suggest. Probably an easier
> approach would be to create a sub-type of ScaleTransform that computes
> CenterX and CenterY dynamically.
>
> Michael
> Microsoft MVP (C# / WPF)
>

My System SpecsSystem Spec
Old 02-21-2006   #4 (permalink)
Michael Jacobs [MSFT]


 
 

Re: Applying a centered ScaleTransform via a Style

Instead of setting the CenterX and CenterY properties of the ScaleTransform,
set the RenderTransformOrigin property of the object to 0.5,0.5. That will
center your ScaleTransform automatically. See
http://windowssdk.msdn.microsoft.com...formOrigin.asp
for more information about the RenderTransformOrigin property.

****
Mike Jacobs [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.

****

"Pascal Bourque" <bourquep@xceedsoft.com> wrote in message
news:uYS6d7qJGHA.3856@TK2MSFTNGP12.phx.gbl...
> Thanks for the suggestions, Michael! I will try deriving form
> ScaleTransform and post the results here!
>
> Pascal
>
> Michael Latta wrote:
>> There is no way to place an expression as an attribute value, and I do
>> not believe binding will solve this either, although you might be able to
>> bind the CenterX and CenterY properties to the control on which it is
>> applied. If that worked you could then create attached properties that
>> are really derived values using the expression you suggest. Probably an
>> easier approach would be to create a sub-type of ScaleTransform that
>> computes CenterX and CenterY dynamically.
>>
>> Michael
>> Microsoft MVP (C# / WPF)
>>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Set Desktop Background as Centered Vista General
Font Size - XP style vs Vista style Vista General
Font Size - XP style vs Vista style Vista General
Font Size - XP style vs Vista style Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46