WPF 窗口样式在运行时不起作用 [英] WPF Window Style not working at runtime

查看:42
本文介绍了WPF 窗口样式在运行时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2010 Express (C#) 中创建了一个 WPF 应用程序,并将下面的文本添加到 App.xaml 中的 Application.Resources.我在设计器中看到应用到窗口的样式,但是当我运行应用程序时,窗口背景是白色的.

I created a WPF application in Visual Studio 2010 Express (C#) and added the text below to the Application.Resources in App.xaml. I see the style applied to the window in the designer, but when I run the application, the window background is white.

如果这是一个因素,请在 MacBook Pro 上的 BootCamp 上运行 Windows XP.

Running in Windows XP on BootCamp on a MacBook Pro if that is a factor.

提前致谢,

基督徒

    <Style TargetType="{x:Type Window}">
        <Setter Property="Background">
            <Setter.Value>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Offset="0" Color="WhiteSmoke" />
                    <GradientStop Offset="1" Color="Silver" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>

        <Setter Property="Padding" Value="20" />
    </Style>

推荐答案

Microsoft 已重现该问题,看起来可能是 WPF 4.0 中的错误.

Microsoft have replicated the problem and it looks like it might be a bug in WPF 4.0.

https://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references

根据提交错误的人所做的研究,我获取了包含在合并资源字典中的所有单独的 XAML 资源文件,并将样式文本剪切并粘贴到单个 UberStyles.xaml 文件中.我避免使用 MergedDictionaries.

Following the research done by the person who submitted the bug, I took all of our individual XAML resource files that are included into the merged resource dictionary and cut and paste the style text into a single UberStyles.xaml file. I avoided all use of MergedDictionaries.

这解决了问题,我的 WPF 3.5 应用程序中的样式信息返回到我的 WPF 4.0 应用程序.

This solved the problem and my style information from my WPF 3.5 application came back against my WPF 4.0 application.

在我看来,这是 WPF 4.0 中的一个明显错误 - 我不确定您如何将其转换为功能,并且该行为未记录在案.我有点担心这对整个 WPF 4.0 平台的影响.您可能会认为这会在 Visual Studio 2010 版本的测试中被发现!

To my eye this is a clear bug in WPF 4.0 - I'm not exactly sure how you'd cast this as a feature and the behavior is undocumented. I'm a little concerned of the implications of this for the WPF 4.0 platform as a whole. You would have thought this would have been caught in the testing of the Visual Studio 2010 Release!

无论如何,希望这会有所帮助.自从两周前我们升级到 VS2010 以来,我一直被这个错误逼疯了.

Anyway, hope this helps. I've been driven crazy by this bug since we upgraded to VS2010 two weeks ago.

这篇关于WPF 窗口样式在运行时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆