【发布时间】:2015-05-26 23:16:41
【问题描述】:
我有一个自定义日历样式和一个自定义 DatePicker 样式。
MyCustomSkin.xaml 中的代码(来自我的库项目)
<Style TargetType="{x:Type Calendar}">
<Setter Property="Background" Value="Red"/>
</Style>
<Style TargetType="{x:Type DatePicker}">
<Setter Property="Background" Value="Green"/>
</Style>
它们都在我的应用程序中引用的 MyCustomSkin.xaml ResourceDictionary(生成 MyCustomSkin.dll 的单独解决方案)中。
我的 App.xaml 中的代码(来自我的应用程序)
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyCustomSkin;component/MyCustomSkin.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainWindow.xaml 中的代码(来自我的应用程序)
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow">
<Grid>
<DatePicker HorizontalAlignment="Right" />
<Calendar HorizontalAlignment="Left"/>
</Grid>
</Window>
当我在我的应用程序中创建日历时(没有指定任何样式),背景是红色的。 当我在我的应用程序中创建 DatePicker 时(未指定任何样式),背景是绿色,但其日历的背景是系统日历的背景(=> 不是红色)。
为什么?我想我正在用我的覆盖所有系统日历。为什么在 DatePicker 的 Calendar 上应用了 Calendar 的自定义样式而不是?
谢谢!
【问题讨论】:
标签: c# wpf datepicker calendar styles