Freigeben über


We Learned XAML at TechiesOnly UG meeting tonight!

Thanks to Rolf, Bruce and Alex - your patience with all our questions are much appreciated! 

I built my first WPF app and am sold on the value of Blend even for developers. One more reason to pick up Team Suite and get Expression included. The below is what I drew in Blend with drag & drop.

image

Yes, not pretty. Blame the student in this case. Then, with just two or three clicks, I set up a storyboard to change the colour of the rectangle, hooked up an event trigger to have a button click cause the storyboard to activate, and viola. Hello Animation World demo done!

<Window x:Class="TechiesOnlyXamlPractice.Window1"

   xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"

   xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"

   Title="Window1" Height="394" Width="422">

    <Window.Resources>

        <Storyboard x:Key="sbRectangleColourChange">

            <ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">

                <SplineColorKeyFrame KeyTime="00:00:02" Value="#FF212DB7"/>

            </ColorAnimationUsingKeyFrames>

        </Storyboard>

    </Window.Resources>

    <Window.Triggers>

        <EventTrigger RoutedEvent="ButtonBase.Click" SourceName="btn1">

            <BeginStoryboard Storyboard="{StaticResource sbRectangleColourChange}" x:Name="sbRectangleColourChange_BeginStoryboard"/>

        </EventTrigger>

    </Window.Triggers>

    <Grid>

        <Button Name="btn1" Margin="18,18,0,0" Height="43" VerticalAlignment="Top" Width="97" HorizontalAlignment="Left">Hello World</Button>

        <Rectangle Margin="67.333,100.667,65.333,84" Fill="#FFB72121" Stroke="#FF000000" x:Name="rectangle"/>

    </Grid>

</Window>

 

For those of you interested in "templates" of code, take a look at Code Snippets in Visual Studio 2008. For examples, see https://www.gotcodesnippets.net/