PrefaceThere a lot of advanced articles on WPF and their desktop applications reflect a lot of experience. But sometimes the learning curve can be steep, as may be a large gap between those at the advanced level and those at the beginning level. This article is an attempt to step through the building process. In any form of programming, the best way to learn how to program is to read well-written programs. This paper will dive into a seemingly complicated WPF application. The XAML code will appear long-winded and the code-behind relatively simple. So we'll start by using either Expression Blend or visual Studio 2008 (or 2010) to make and develop this application. Once we are finished, we will examine how it works, and more importantly, why it works. So we begin by starting a new C# WPF application, and call it the default, WPFApp4. We then modify the code in MainWindow.xaml: <Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApp4.MainWindow"
Title="Color Spinner" Height="370" Width="270"> <Window.Resources>
<Storyboard x:Key="Spin">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="ellipse1"
Storyboard.TargetProperty= "(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"
RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:10" Value="360"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="ellipse2"Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:10" Value="-360"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="ellipse3"Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="360"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00"
Storyboard.TargetName="ellipse4"Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"RepeatBehavior="Forever">
<SplineDoubleKeyFrame KeyTime="00:00:05" Value="-360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
....The <Window> element is used, unsurprisingly, to define a window. An application might consist of several windows, each of which would be contained in a separate XAML file. This isn’t to say that a XAML file always defines a window, though; XAML files can contain user controls, brushes and other resources, Web pages, and more. There is even a XAML file in the WpfApp4 project that defines the application itself — App.xaml. .Back to MainWindow.xaml, notice that the <Window> element contains some fairly self-explanatory attributes. There are two namespace declarations, one for the global namespace to be used for the XML and one for the x namespace. Both of these are essential for WPF functionality and define the vocabulary for the XAML syntax. Next is a Class attribute, taken from the x namespace. This attribute links the XAML<Window> element to a partial class definition in the code behind, in this case WpfApp4.Window. Read more: Codeproject<Storyboard x:Key="ellipse1"/>
0 comments:
Post a Comment