How can I create Four Button controls with the contents set to a String, a DateTimeObject, an UIElement and A Panel that contains other UIElement objects?

The example Extensible Application Markup Language (XAML) version could use the <Button.Content> tags around the content of each button, but it is not necessary. The Four buttons can be created as follows. [XAML] <!--Create a Button with a string as its content.--> <Button>This is string content of a Button</Button> <!--Create a Button with a DateTime object as its content.--> <Button xmlns:sys='clr-namespace:System;assembly=mscorlib'> <sys:DateTime>2004/3/4 13:6:55</sys:DateTime> </Button> <!--Create a Button with a single UIElement as its content.--> <Button> <Rectangle Height='40' Width='40' Fill='Blue'/> </Button> <!--Create a Button with a panel that contains multiple objects as its content.--> <Button> <StackPanel> <Ellipse Height='40' Width='40' Fill='Blue'/> <TextBlock TextAlignment='Center'>Button</TextBlock> </StackPanel> </Button>

How do I enumerate child objects in a visual tree ?

WPF has a “VisualTreeHelper” class that provides the functionality to retrieve the parent objects of a visual object using the GetParent() method and child objects of a visual object using the GetChild() method by specifying the index value of the child. The following code snippet is used to enumerate all the child objects of a visual object. [C#] public void ChildEnum(Visual Visualobj) { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(Visualobj); i++) { Visual childVisual = (Visual)VisualTreeHelper.GetChild(Visualobj, i); VisualEnum(childVisual); } }

How can I use a DoubleAnimation to rotate the textblock ?

The following example uses a DoubleAnimation to rotate the textblock. The textblock performs a full rotation over a duration of 20 seconds and then continues to repeat the rotation. [XAML] <TextBlock Name='MyRotatingText' Margin='20' Width='640' Height='100' FontSize='48' FontWeight='Bold' Foreground='Teal' > This is rotating text <TextBlock.RenderTransform> <RotateTransform x:Name='MyRotateTransform' Angle='0' CenterX='230' CenterY='25'/> </TextBlock.RenderTransform> <!-- Animates the text block’s rotation. --> <TextBlock.Triggers> <EventTrigger RoutedEvent='TextBlock.Loaded'> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName='MyRotateTransform' Storyboard.TargetProperty='(RotateTransform.Angle)' From='0.0' To='360' Duration='0:0:10' RepeatBehavior='Forever' /> </Storyboard> </BeginStoryboard> </EventTrigger> </TextBlock.Triggers> </TextBlock>

How can I create a combined hard and soft shadow ?

This can be done as follows. [XAML] <!-- Hard shadow on top of soft shadow. --> <TextBlock Text='Shadow Text' Foreground='CornflowerBlue'> <TextBlock.BitmapEffect> <BitmapEffectGroup> <BitmapEffectGroup.Children> <DropShadowBitmapEffect ShadowDepth='5' Direction='330' Color='DarkSlateBlue' Opacity='0.75' Softness='0.50' /> <DropShadowBitmapEffect ShadowDepth='2' Direction='330' Color='Maroon' Opacity='0.5' Softness='0.0' /> </BitmapEffectGroup.Children> </BitmapEffectGroup> </TextBlock.BitmapEffect> </TextBlock>

How do I rearrange the columns in a DataGrid ?

The columns appear in the order in which their column styles were added to the tablestyle, being used by the grid. If you want to change this order, you need to create a new table style and add the column styles in the order you want things to appear. Here are some code snippets that suggest how to do this. [C#] public void MoveColumn(DataGrid _dataGrid, string _mappingName, int fromCol, int toCol) { if(fromCol == toCol) return; DataGridTableStyle oldTS = _dataGrid.TableStyles[_mappingName]; DataGridTableStyle newTS = new DataGridTableStyle(); newTS.MappingName = _mappingName; for(int i = 0; i < oldTS.GridColumnStyles.Count; ++i) { if(i != fromCol && fromCol < toCol) newTS.GridColumnStyles.Add(oldTS.GridColumnStyles[i]); if(i == toCol) newTS.GridColumnStyles.Add(oldTS.GridColumnStyles[fromCol]); if(i != fromCol && fromCol > toCol) newTS.GridColumnStyles.Add(oldTS.GridColumnStyles[i]); } _dataGrid.TableStyles.Remove(oldTS); _dataGrid.TableStyles.Add(newTS); } Sample usage private void button1_Click(object sender, System.EventArgs e) { MoveColumn( myDataGrid, 'Customers', 3, 1 ); }