我有一个如下创建的日历
<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>
现在,我还有另一个日历控件,该控件具有漂亮的样式,可以访问样式,但是当我应用它时,会出现错误
Style="{StaticResource CalendarBaseStyle}"
日历目标类型与元素类型不匹配... 这就是我的风格
<Style x:Key="CalendarBaseStyle" TargetType="{x:Type Calendar}">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
...
如您所见,我的日历是由Uniform Grid制成的,那么如何将日历样式应用于它呢?
答案 0 :(得分:2)
将样式目标类型更改为控件的类型,例如:
xmlns:myControls="clr-namespace:MyNamespace.Controls"
....
<Style x:Key="CalendarBaseStyle" TargetType="{x:Type myControls:MyCalendarControl}">
....