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>

What is XAML?

XAML is an extensible markup language based on XML. XAML can be thought of as a declarative script for creating .NET 3.0 UI. It is particularly used in WPF as a user interface markup language to define UI elements, data binding, eventing and other features. It is also used in Windows Workflow Foundation (WF), in which the workflows themselves can be defined in XAML code.

What is WPF?

Windows Presentation Foundation (WPF) is the presentation subsystem feature of the .NET Framework 3.0. It is pre-installed in as a part of Windows Vista, It is also available for installation on Windows XP SP2 and Windows Server 2003. It supports the rich User Experiences (UX) that have been made possible by advances in hardware and technology since the GDI based UI architecture was initially designed in the 1980’s. Also refer to the separate section on XAML in this FAQ