What is Style Inheritance?

 Posted by Ddd on 2/24/2011 | Category: WPF Interview questions | Views: 3200 | Points: 40
Answer:

It is the technique through which one style aquires the features of another style

It is implemented through BasedOn property of the Style class.

example:
<Window x:Class="WpfApplication14jan.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style x:Key="One" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="Green"/>
</Style>
<!-- This is how the style inheritance is implemented-->
<Style x:Key="Two" BasedOn="{StaticResource One}" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow"/>
</Style>
</Window.Resources>
<Button Height="100" Width="100" Style="{StaticResource Two}" Content="Welcome">
</Button>
</Window>


//Note:
//When you run the WPF Form, the Button will aquire the Formatting from both the
//styles


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Tripati_tutu on: 2/26/2011 | Points: 10
Nice one.

Login to post response