How can I animate a BorderThickness value ?

BorderThickness can be animated by using the ‘ThicknessAnimation’ class. The following example animates the thickness of a border by using the ThicknessAnimation. The example uses the ‘BorderThickness’ property of Border. [XAML] <!– This example shows how to use the ThicknessAnimation to create an animation on the BorderThickness property of a Border. –> <Page xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ > <StackPanel Orientation=’Vertical’ HorizontalAlignment=’Center’> <Border Background=’#99FFFFFF’ BorderBrush=’#CCCCFF’ BorderThickness=’1′ Margin=’0,60,0,20′ Padding=’20’ > <Border.Triggers> <EventTrigger RoutedEvent=’Border.Loaded’> <BeginStoryboard> <Storyboard> <!– BorderThickness animates from left=1, right=1, top=1, and bottom=1 to left=28, right=28, top=14, and bottom=14 over one second. –> <ThicknessAnimation Storyboard.TargetProperty=’BorderThickness’ Duration=’0:0:1.5′ FillBehavior=’HoldEnd’ From=’1,1,1,1′ To=’28,14,28,14′ /> </Storyboard> </BeginStoryboard> </EventTrigger> </Border.Triggers> <TextBlock> This example shows how to use the ThicknessAnimation to create an animation on the BorderThickness property of a Border. </TextBlock> </Border> </StackPanel> </Page>

What way can a custom class can be defined in XAML ?

Custom classes can be defined in the Window.Resoures of the XAML page. This can be done with the following code snippets. [XAML] <Window.Resources> <local:BoolToVisibilityConverter x:Key=”BoolToVisConverter”/> </Window.Resources> <Grid> <Button Visibility=”{Binding IsVisible,Converter={StaticResource BoolToVisConverter}}”/> </Grid>

Performance gets reduced even after navigating away from a page that contains animation. How do we handle this issue ?

The scenario is such that the animations in the page will continue to play until it is garbage collected, even when the page is navigated away to another page holding the memory and system resources for animation. There will be severe drop in performance when more animations are running in a page. To overcome this issue, ‘Unloaded’ event of the page can be used to remove the animations from the page such that the animations don’t consume memory and system resources.

How do I create a Borderless Window in WPF ?

To make the window display without this gray border, you need to set the ‘ResizeMode’ property of the window to ’NoResize’. [XAML] <Window x:Class=’BorderlessWindow.Window1′ xmlns=’http://schemas.microsoft.com/winfx/2006/xaml/presentation’ xmlns:x=’http://schemas.microsoft.com/winfx/2006/xaml’ Title=’BorderlessWindow’ Height=’200′ Width=’200′ Background=’White’ WindowStyle=’None’ ResizeMode=’NoResize’> <Border Padding=’5′ BorderBrush=’#feca00′ BorderThickness=’3′ Width=’150′ Height=’150′> <TextBlock>Learn WPF!</TextBlock> </Border> </Window>

How can I restrict the use of style for certain types of controls ?

If you want to enforce that a style can be applied to a particular type only, you can set its ‘TargetType’ property. For example, the following style can only be applied to a button (or a subclass of a button). [XAML] <Style x: key=’buttonStyle’ TargetType='{x:Type Button}’> <Setter Property=’ Button.FontSize’ Value=’22’/> <Setter Property=’ Button.Background’ Value=’Purple’/> <Setter Property=’ Button.Foreground’ Value=’While’/> <Setter Property=’ Button.Height’ Value=’50’/> <Setter Property=’ Button.Width’ Value=’50’/> <Setter Property=’ Button.RenderTransFormOriginal’ Value=’.5,.5’/> <Setter Property=’ Button.RenderTransForm’/> <Setter.Value > <RotateTransform Angle=’10’/> </Setter.Value> </Setter> </Style>