0

I can not apply the Style for custom UserControl. Styles for TextBlock and MyControl are in the same dictionary. Style for TextBlock used without problems. But for MyControl style is not applied. Why?

// XAML
xmlns:local="clr-namespace:MyControlNameSpace"

 <Grid>
   <TextBlock x:Name="text"  Style="{DynamicResource TextStyle}"/>
   <local:MyControl x:Name="control" Style="{DynamicResource ControlStyle}"/>
 </Grid>

// RESOURCE DICTIONARY
  <Style x:Key="ControlStyle" TargetType="{x:Type local:MyControl}">
        <Setter Property="Height" Value="Auto"/>
        <Setter Property="Width" Value="Auto"/>
        <Setter Property="Foreground" Value="White"/>
        <Setter Property="ColorMain" Value="Black"/>
        <Setter Property="Margin" Value="2"/>
  </Style>

  <Style x:Key="TextStyle" TargetType="{x:Type TextBlock}">
       ....
       <Setter Property="FontSize" Value="32"/>
       ...
   </Style>
     //PART of CS           
     public partial class MyControl: UserControl   {    ....   }
eran otzap
  • 12,293
  • 20
  • 84
  • 139
Mixer
  • 1,292
  • 3
  • 22
  • 41

1 Answers1

0

Try changing

<Setter Property="ColorMain" Value="Black"/>

To

<Setter Property="Background" Value="Black"/>
narendra
  • 163
  • 1
  • 6