How can I add a CommandBinding to a window using markup?

CommandBinding can be added to a window using markup. Note that in XAML, the CommandBindingCollection is not declared in the markup as an element and the collection object is inferred by the type that the property takes and you populate the property element with one or more CommandBinding elements. [XAML] <Window.CommandBindings> <CommandBinding Command='ApplicationCommands.Open' Executed='OpenCmdExecuted' CanExecute='OpenCmdCanExecute'/> </Window.CommandBindings>

How do I access extended properties from a XAML tempalte?

Here is how you would access a Canvas.Left extended property for example: <DataTemplate x:Key='MyTemplate1'> <Path Data='{Binding Geometry}'> <Path.RenderTransform> <!-- The Item property returns a visual hosted inside the Canvas --> <RotateTransform Angle='60' CenterX='{Binding Item.(Canvas.Left)}' CenterY='{Binding Item.(Canvas.Top)}' > </RotateTransform> </Path.RenderTransform> </Path> </DataTemplate>

How can I create a Style deriving from another Style

Perhaps you want your two ‘TextBlock’ elements to share some property values such as the FontFamily and the centered HorizontalAlignment, but you also want the text ‘My Pictures’ to have some additional properties. You can do that by creating a new style that is based on the first style, as shown here. [XAML] <Window.Resources> ... <!--A Style that extends the previous MyBaseStyle Style--> <!--This is a 'named style' with an x:Key of MyDerivedStyle--> <Style BasedOn='{StaticResource {x:Type MyBaseStyle}}' TargetType='TextBlock' x:Key='MyDerivedStyle'> <Setter Property='FontSize' Value='26'/> <Setter Property='Foreground'> <Setter.Value> <LinearGradientBrush StartPoint='0.5,0' EndPoint='0.5,1'> <LinearGradientBrush.GradientStops> <GradientStop Offset='0.0' Color='#90DDDD' /> <GradientStop Offset='1.0' Color='#5BFFFF' /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </Setter.Value> </Setter> </Style>

How can I set an attached property in code?

The following example shows how you can set an attached property in code. [C#] DockPanel myDockPanel = new DockPanel(); CheckBox myCheckBox = new CheckBox(); myCheckBox.Content = 'Hello'; myDockPanel.Children.Add(myCheckBox); DockPanel.SetDock(myCheckBox, Dock.Top);

When I try to add multiple controls to a button it shows an error, how do I add multiple controls to a button?

Most of UI Elements in WPF can contain only a single child element, therefore, when you add a control to a button, an error stating that the control has a child and only one child can be added to the control is generated. To overcome this error add layouts like StackPanel inside the control and add multiple controls inside that StackPanel. The following code snippet will cause the error mentioned above. [XAML] <Button Height='100'> <RadioButton Content='Button1' /> <RadioButton>Button 2</RadioButton>> </Button> A StackPanel can be used inside the button to have multiple controls inside the button. The following lines of code can be used to overcome the error. [XAML] <Button Height='100'> <StackPanel Orientation='Horizontal'> <RadioButton Content='Button1'/> <RadioButton>Button 2</RadioButton> </StackPanel> </Button>