Hello, I tried to use Background property with following code but couldn't get it work. Where the bug might be?
Cheers,
<Grid x:Name="mainLayout" Background="White" SizeChanged="mainLayout_SizeChanged" >
<Grid.Resources>
<Style TargetType="RadioButton" x:Key="tabishRadioButton">
<Setter Property="Background" Value="LightGray"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<Grid x:Name="RootElement">
<Border x:Name="tabBorder"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="4,4,0,0"
Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}"
VerticalAlignment="Center"
HorizontalAlignment="Center" Visibility="Visible"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<RadioButton VerticalAlignment="Top"
Height="30"
Width="100"
x:Name="Tab"
Content="tab1Content"
Style="{StaticResource tabishRadioButton}"
Visibility="Visible"
Checked="Tab_Checked"/>
<RadioButton VerticalAlignment="Top"
Height="30"
Width="100"
Content="tab2Content"
x:Name="Tab2"
Margin="2,0,0,0"
Visibility="Visible"
Style="{StaticResource tabishRadioButton}"
Checked="Tab2_Checked"/>
<RadioButton VerticalAlignment="Top"
Height="30"
Width="100"
Content="tab3Content"
x:Name="Tab3"
Margin="2,0,0,0"
Visibility="Visible"
Style="{StaticResource tabishRadioButton}"
Checked="Tab3_Checked"/>
</StackPanel>
// Codebehind .cs
private void Tab_Checked(object sender, RoutedEventArgs e)
{
tab2Content.Visibility = Visibility.Visible;
SetTabColor(Tab, Colors.LightGray);
}
public static readonly DependencyProperty BackgroundProperty =
DependencyProperty.Register("Background", typeof(SolidColorBrush),
typeof(RadioButton), null);
public void SetTabColor(RadioButton btn, Color Col)
{
btn.SetValue(RadioButton.BackgroundProperty, new SolidColorBrush(Col));
}