【问题标题】:Apply styles to wpf Custom calendars将样式应用于 wpf 自定义日历
【发布时间】:2019-03-11 07:14:52
【问题描述】:

我有一个如下创建的日历

<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 制作的,那么如何将日历样式应用到它呢?

【问题讨论】:

  • 请发布一个完整的例子。不清楚这两段代码是如何一起使用的

标签: wpf xaml calendar styles uniformgrid


【解决方案1】:

将样式目标类型更改为您的控件的类型,例如:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-25
    • 2014-06-16
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多