如何在 WPF 应用程序中禁用 XP 主题?
我有一个 WPF 应用程序(.NET 3.0、VS2008),它在选项卡控件中显示数据。 该应用程序中几乎所有控件都需要自定义颜色:基本上是白色前景和绿色背景。
我的问题是,当 XP 主题(比如 Luna)处于活动状态时,它会自动应用于渲染控件,以便我的白色文本写在......白色背景上。 例如,在活动选项卡项目标题上:
我尝试过:
- 从生成的应用程序中删除嵌入的清单文件(在项目属性中):无用。
强制在应用程序资源中使用 Windows 经典主题:
;
这最后一次尝试对所有控件都非常有效,但选项卡控件除外,它仍然如上所示。
任何想法 ?
更新:我怀疑这种行为是由于我必须应用于选项卡控件的自定义样式造成的:
<Window.Resources>
<Style x:Key="Custom">
<Setter Property="Control.Background" Value="#FF47C7C8" />
<Setter Property="Control.Foreground" Value="White" />
</Style>
<Style TargetType="TabControl" BasedOn="{StaticResource Custom}" />
</Window.Resources>
那么如何获得具有自定义颜色的经典主题?
I have a WPF application (.NET 3.0, VS2008) that displays data in a tab control. Custom colors are required on virtually all controls in this application : basically white foreground and green background.
My problem is that when an XP theme (say Luna) is active, it is automatically applied to render controls so that my white text is written on ... a white background. For instance on the active tab item header :
I have tried :
- to remove the embedded manifest file from the generated application (in the project properties) : useless.
to force the use of the Windows Classic theme in the application resources :
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/PresentationFramework.Classic;V3.0.0.0;31bf3856ad364e35;component/themes/classic.xaml" /> </ResourceDictionary.MergedDictionaries>
This last attempt worked great for all controls, except the tab control which still displays as above.
Any idea ?
Update : I am suspecting this behaviour is due to the custom style I have to apply to the tab control :
<Window.Resources>
<Style x:Key="Custom">
<Setter Property="Control.Background" Value="#FF47C7C8" />
<Setter Property="Control.Foreground" Value="White" />
</Style>
<Style TargetType="TabControl" BasedOn="{StaticResource Custom}" />
</Window.Resources>
So how can I get the classic theme with custom colors ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了确保跨操作系统的行为和外观一致,最好的选择是重新模板化 TabItem 控件,然后在选择 TabItem 时使用触发器修改新模板的一部分。 尝试如下操作:
好的机会!
Your best bet, to ensure a consistent behavior and appearance across operating systems, would be to re-template the TabItem control and then use a Trigger to modify a part of your new template when a TabItem is selected. Try something like the following:
Bon chance!
为什么不使用 WPF Futures 项目中的 WPF 主题!
WPF 主题
替代文本 http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName= wpf&DownloadId=62497
Why don't you use the WPF Themes from the WPF Futures project!
WPF Themes
alt text http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=wpf&DownloadId=62497