Apply styles to wpf Custom calendars

167 views Asked by At

I have a calendar created as follows

<Grid>
        <Rectangle Margin="2" Height="25" Name="borderRectangle" VerticalAlignment="Top" Fill="#FFEAEEF9" />
        <Button Name="titleButton" Style="{StaticResource ButtonStyle}" Margin="30,1,30,0"  FlowDirection="RightToLeft" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" Focusable="True" Click="titleButton_Click" Height="25" VerticalAlignment="Top" FontWeight="Bold" IsTabStop="True" TabIndex="0">خرداد 1397</Button>
        <Button Name="previousButton" Style="{StaticResource ButtonStyle}" Height="25" HorizontalAlignment="Right" Margin="0,2,12,0"  VerticalAlignment="Top" Width="23"  Background="Transparent" BorderThickness="0" Padding="0"  FontFamily="Arial" FontSize="14" BorderBrush="Transparent" Click="previousButton_Click" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" IsTabStop="True" TabIndex="0">►</Button>
        <Button Name="nextButton" Style="{StaticResource ButtonStyle}" Height="25" HorizontalAlignment="Left" Margin="12,2,0,0" VerticalAlignment="Top" Width="23"  Background="Transparent" BorderThickness="0" Padding="0" FontFamily="Arial" FontSize="14" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderBrush="Transparent"  Click="nextButton_Click" IsTabStop="True" TabIndex="0">◄</Button>
        <UniformGrid Margin="3,26,3,2" Name="monthUniformGrid" Rows="7" Columns="7"  FlowDirection="RightToLeft" />
        <UniformGrid Margin="3,26,3,2" Name="yearUniformGrid"  Columns="3" Rows="4" FlowDirection="RightToLeft" />
        <UniformGrid Margin="3,26,3,2" Name="decadeUniformGrid"  Columns="3" Rows="4" FlowDirection="RightToLeft" />
    </Grid>

And the result is this way Custom Calendar

Now I have another calendar control that has beautiful styles I have access to styles, but when I apply it, I get an error

Style="{StaticResource CalendarBaseStyle}"

calendar target type does not match type of element... and this is my style

 <Style x:Key="CalendarBaseStyle" TargetType="{x:Type Calendar}">
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
...

As you can see, my calendar is made by Uniform Grid So how can I apply the calendar style to it?

1

There are 1 answers

0
Dipen Shah On BEST ANSWER

Change the style target type to type of your control, for example:

xmlns:myControls="clr-namespace:MyNamespace.Controls"
....
<Style x:Key="CalendarBaseStyle" TargetType="{x:Type myControls:MyCalendarControl}">
....