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>
How do I change the shape of the button to an ellipse?
The button’s shape can be changed to any shape by applying the control template to a button. The following code snippet is used to change the shape of a button to an ellipse. [XAML] <ControlTemplate x:Key=’Temp1′ TargetType='{x:Type Button}’> <Grid> <Ellipse x:Name=’Ell’ Width='{TemplateBinding Width}’ Height=’50’> <Ellipse.Fill> <LinearGradientBrush StartPoint=’0,0.5′ EndPoint=’1,0.5′> <GradientStop Offset=’0.3′ Color=’YellowGreen’/> <GradientStop Offset=’1′ Color=’Green’/> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> <Viewbox> <ContentControl Margin=’10’ Content='{TemplateBinding Content}’ FontSize=’11’ HorizontalContentAlignment=’Center’ Foreground=’AntiqueWhite’/> </Viewbox> </Grid> </ControlTemplate> <Button Name=’Button1′ Template='{StaticResource Temp1}’ Height=’50’ Width=’80’>Templated Button</Button>
How do I create custom layout for StatusBar items?
StatusBar uses a DockPanel as an item template and docks all the items in the control to the left except for the last item. The last item takes the rest of the space in the statusbar. To have a custom layout for the statusbar control, you can change the DockPanel to a StackPanel, WrapPanel etc. You can also align the items in the statusbar using the DockPanel.Dock property for each statusbar item. The following lines of code are used to change the alignment of the statusbar items. [XAML] <StatusBar Height=’30’ VerticalAlignment=’Bottom’ Background=’Azure’> <StatusBarItem DockPanel.Dock=’Right’> <TextBlock Text=’Welcome to WPF!!’/> </StatusBarItem> <StatusBarItem> <TextBlock Text=’Hello World! ‘/> </StatusBarItem> </StatusBar>