Rotating an Image with WPF in XAML

13 11 2009

So… pasting code is still tricky. But I think this will work. This code is what I used when I wanted to rotate an Image object declared in XAML. To be clear, this allows me to create a rotating image without any C# or VB code. Personally I chose to rotate this picture:

Loading 2
The CenterX and CenterY property of RotateTransform should be half of the Image objects width and height. This can be found by using databindings but that’s another post completely.  

<Style x:Key="AnimationImage" TargetType="{x:Type Image}">

    <Setter Property="RenderTransform">

        <Setter.Value>

            <RotateTransform Angle="0" CenterX="20" CenterY="20" />

        </Setter.Value>

    </Setter>

 

    <Style.Triggers>

        <Trigger Property="IsEnabled" Value="true">

            <Trigger.EnterActions>

                <BeginStoryboard>

                    <Storyboard>

                       <DoubleAnimation Storyboard.TargetProperty="RenderTransform.Angle"

                        From="0" To="360" Duration="0:0:1.5" RepeatBehavior="Forever" />

                    </Storyboard>

                </BeginStoryboard>

            </Trigger.EnterActions>

        </Trigger>

    </Style.Triggers>
</Style>





First Post

13 11 2009

This blog will be a place for me to contribute to the hive-mind that is Internet. I will write mostly about the work I do and mainly solutions to problems I’ve encountered. I enjoy developing for Microsoft Silverlight and Windows Presentation Foundation (WPF). Many of my posts will be regarding these two emerging technologies. One of my guilty tech-pleasures is Microsoft Surface which is technology I’d like to develop for but don’t see it in my foreseeable future.

The name Fragile Development is both a pun (man do I love a good pun) and a nod to the touch-n-go, trial-n-error style of development one often uses while learning a new technology.

It's-a-me!








Follow

Get every new post delivered to your Inbox.