How can I use Event Trigger to control a StoryBoard after it is started ?
The following example uses controllable storyboard actions to interactively control a storyboard. [XAML] <Page xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ WindowTitle=’Controlling a Storyboard’ > <StackPanel Margin=’20’ > <!– This rectangle is animated. –> <Rectangle Name=’myRectangle’ Width=’100′ Height=’20’ Margin=’12,0,0,5′ Fill=’#AA3333FF’ HorizontalAlignment=’Left’ /> <!– This StackPanel contains all the Buttons. –> <StackPanel Orientation=’Horizontal’ Margin=’0,30,0,0′> <Button Name=’BeginButton’>Begin</Button> <Button Name=’PauseButton’>Pause</Button> <Button Name=’ResumeButton’>Resume</Button> <Button Name=’SeekButton’>Seek</Button> <Button Name=’SkipToFillButton’>Skip To Fill</Button> <Button Name=’SetSpeedRatioButton’>Triple Speed</Button> <Button Name=’StopButton’>Stop</Button> <StackPanel.Triggers> <!– Begin the Storyboard –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’BeginButton’> <BeginStoryboard Name=’MyBeginStoryboard’> <Storyboard > <DoubleAnimation Storyboard.TargetName=’myRectangle’ Storyboard.TargetProperty=’Width’ Duration=’0:0:5′ From=’100′ To=’500′ /> </Storyboard> </BeginStoryboard> </EventTrigger> <!– Pause the Storyboard –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’PauseButton’> <PauseStoryboard BeginStoryboardName=’MyBeginStoryboard’ /> </EventTrigger> <!– Resume the Storyboard –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’ResumeButton’> <ResumeStoryboard BeginStoryboardName=’MyBeginStoryboard’ /> </EventTrigger> <!– Seek one second into the storyboard’s active period. –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’SeekButton’> <SeekStoryboard BeginStoryboardName=’MyBeginStoryboard’ Offset=’0:0:1′ Origin=’BeginTime’ /> </EventTrigger> <!– Skip to Fill –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’SkipToFillButton’> <SkipStoryboardToFill BeginStoryboardName=’MyBeginStoryboard’ /> </EventTrigger> <!– Stop the Storyboard –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’StopButton’> <StopStoryboard BeginStoryboardName=’MyBeginStoryboard’ /> </EventTrigger> <!– Triple the speed of the Storyboard –> <EventTrigger RoutedEvent=’Button.Click’ SourceName=’SetSpeedRatioButton’> <SetStoryboardSpeedRatio SpeedRatio=’3′ BeginStoryboardName=’MyBeginStoryboard’ /> </EventTrigger> </StackPanel.Triggers> </StackPanel> </StackPanel> </Page>
How can I get an enumerator to the ContentControl’s logical child elements ?
We cant get an enumerator to the ContentControl’s logical child elements through the XAML code. But it can be implemented in C# coding as follows. [C#] protected internal override IEnumerator LogicalChildren { get; }
How can I apply the TypeConverter Attribute ?
In order for your custom type converter to be used as the acting type converter for a custom class, you must apply the .NET Framework “TypeConverter” attribute to your class definition. The Converter Type ’Name’ that you specify through the attribute must be the type name of your custom type converter. With this attribute applied, when an XAML processor handles values where the property type uses your custom class type, it can input strings and return object instances. You can also provide a type converter on a per-property basis. Instead of applying a .NET Framework “TypeConverter” attribute to the class definition, apply it to a property definition (the main definition, not the get / set implementations within it). The type of the property must match the type that is processed by your custom type converter. With this attribute applied, when an XAML processor handles values of that property, it can process input strings and return object instances. The per-property type converter technique is particularly useful if you choose to use a property type from Microsoft .NET Framework or from some other library where you cannot control the class definition and cannot apply a “TypeConverter” attribute there.
Which namespace is used to associate namespace identifiers with element names ? Is there any effect on the attributes ?
There is one more type of namespace declaration that can be used to associate namespace identifiers with element names. This is known as a default namespace declaration which uses the following syntax. xmlns=’<namespace identifier>’ Notice that there is no prefix. When a default namespace declaration is used on an element, all unqualified element names within it’s scope are automatically associated with the specified namespace identifier. Default namespace declarations, however, have absolutely no effect on attributes. The only way to associate an attribute with a namespace identifier is through a prefix. Consider the following example. [XAML] <d:student xmlns:d=’http://www.develop.com/student’ xmlns=’urn:foo’ id=’3235329’ > <name>Jeff Smith</name> <language xmlns=’’>C#</language> <rating>35</rating> </d:student> Here, ‘student’ is from the http://www.develop.com/student namespace while ‘name’ and ‘rating’ are from the default namespace urn:foo. The ’id’ attribute doesn’t belong to a namespace since attributes aren’t automatically associated with the default namespace identifier. This example also illustrates that you can undeclare a default namespace by simply setting the default namespace identifier back to the empty string as shown in the language element (remember you cannot do this with prefix declarations). As a result, the language element also doesn’t belong to a namespace. The syntax for default namespaces was designed for convenience but they tend to cause more confusion than their worth. The confusion typically stems from the fact that elements and attributes are treated differently and it’s not immediately apparent that nested elements are being assigned the default namespace identifier. Nevertheless, in the end, choosing between prefixes and default namespaces is mostly a matter of style, except when attributes come into play.
What are the limitations of Inline Styles and Templates ?
In Extensible Application Markup Language (XAML), style and template properties can technically be set in any one of two ways provided. You can use ’attribute syntax’ to reference a style that was defined within a resource, for example <object Style='{StaticResource myResourceKey}’ …/>. Or you can use ’property element syntax’ to define an inline style for an instance. [XAML] <object> <object.Style> <Style …/> </object.Style> </object> The attribute usage is much more common. A style that is defined inline and not defined in resources is necessarily scoped to the containing element only and cannot be re-used easily because it has no resource key. In general a resource-defined style is more versatile and useful in keeping with the general Windows Presentation Foundation (WPF) programming model principle of separating program logic in code from design in markup. Usually there is no reason to set a style or template inline even if you intend to use that style or template in that location only. Most elements that can take a style or template also support a ’content property’ and a ’content model’. If you only use the logical tree you create through styling or templating once, it would be even easier to just fill that content property with the equivalent child elements in direct markup. This would bypass the style and template mechanisms altogether. Other syntaxes enabled by markup extensions that return an object are also possible with styles and templates. Two such extensions that have possible scenarios include ’TemplateBinding’ and ’Binding’.