How can I animate the thickness of a border by using ThicknessAnimation ?

The following example animates the thickness of a border by using the ‘ThicknessAnimation’ property. The example uses the ’BorderThickness’ property of Border. [XAML] <!– 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>

How can I crop an Image ?

Cropping images is done with the Image.Clip property. For this, use the following code snippets. [XAML] <Image Source=”Test.png”> <Image.Clip> <EllipseGeometry Center=”120,140″ RadiusX=”150″ RadiusY=”150″ /> </Image.Clip> <Image> Reference link: https://www.c-sharpcorner.com/uploadfile/mahesh/clipping-or-cropping-images-in-wpf/

How do I make the Expander button to be justified to the right, rather than the left which is the default ?

If you require justifying the Expander button to the right, you need to set the FlowDirection property to RightToLeft. Note: If you set the FlowDirection to RightToLeft, the content of the expander will also be moved to RightToLeft justification. In order to avoid this, you can set the flow direction to expander content. This can be done with the following code snippets, [XAML] <Expander FlowDirection=”RightToLeft”> <Expander.Header> <TextBlock Text=”Expander header content” Background=”AliceBlue” Width=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=ActualWidth}”/> </Expander.Header> <Grid FlowDirection=”LeftToRight”> <TextBlock Background=”Gray” Text=”Expander body content”/> </Grid> </Expander>

How do I host a Windows Forms control in a WPF application ?

First make sure to add references to ‘System.Windows.Forms’ and ‘System.Windows.Forms.Integration’. Then you need to decide if you will use code, XAML or a combination of both to work with the Windows Forms controls. If you are strictly using code, you would write code similar to the following : [C#] //Instantiate the hosting control WindowsFormsHost host = new WindowsFormsHost(); //Instantiate the Windows Forms control, in this case a button System.Windows.Forms.Button wfButton = new System.Windows.Forms.Button(); wfButton.Text = ‘Windows Forms Button’; // Add the Windows Forms button to the host control host.Children.Add(wfButton); // Add the host control to the WPF element that // you want to parent the control, // in this case it’s a Grid this.grid1.Children.Add(host); If you are using XAML, you still need to add the references to ‘System.Windows.Forms’ and ‘System.Windows.Forms.Integration’, but you will also need to add mapping statements to your XAML that will allow you to refer to the objects that live in these namespaces via XAML: [XAML] <?Mapping XmlNamespace=’wfi’ ClrNamespace=’System.Windows.Forms.Integration’ Assembly=’WindowsFormsIntegration’?> <?Mapping XmlNamespace=’wf’ ClrNamespace=’System.Windows.Forms’ Assembly=’System.Windows.Forms’?> The ‘XMLNamespace’ property provides a way to create a tag that you can use as a namespace prefix in the XAML to refer to the controls within the ‘System.Windows.Forms’ and ‘System.Windows.Forms.Integration’ namespaces. To enable this, you must also create ‘xmlns’ properties in the XAML that maps back to these prefixes as given below : [XAML] <Window x:Class=’AvalonApplication17.Window1′ xmlns=’http://schemas.microsoft.com/winfx/avalon/2005′ xmlns:x=’http://schemas.microsoft.com/winfx/xaml/2005′ xmlns:wfi=’wfi’ xmlns:wf=’wf’ Title=’AvalonApplication17′ Loaded=’WindowLoaded’ > Then you can use XAML to instantiate the WindowsFormsHost control and its subsequent child controls: <Grid x:Name=’grid1′> <wfi:WindowsFormsHost> <wf:Button Text=’Windows Forms Button’/> </wfi:WindowsFormsHost> </Grid>

How can I write Message Loops ?

Message Loops can be written with the following properties. IsThreadModal – returns whether the application has gone modal (e.g., a modal message loop has been pushed). ComponentDispatcher can track this state because the class maintains a count of ‘PushModal’ and ‘PopModal’ calls from the message loop. ThreadFilterMessage and ThreadPreprocessMessage events follow the standard rules for delegate invocations. Delegates are invoked in an unspecified order and all delegates are invoked even if the first one marks the message as handled. ThreadIdle – indicates an appropriate and efficient time to do idle processing (there are no other pending messages for the thread). ThreadIdle will not be raised if the thread is modal. ThreadFilterMessage – raised for all messages that the message pump processes. ThreadPreprocessMessage – raised for all messages that were not handled during ThreadFilterMessage.