【问题标题】:WPF context menu spacing differs on different windows versionsWPF 上下文菜单间距在不同的 Windows 版本上有所不同
【发布时间】:2019-01-09 14:26:24
【问题描述】:

我们面临一个问题,我们发现上下文菜单间距,尤其是分隔符周围的间距在 Windows 10 和 Windows 7 之间有所不同。

抱歉缩放,但很明显,在 windows /top 上)分隔符周围的间距比 Windows 10 中的大。

奇怪的是,我们查看了 vosual 树,而 windows 10 中的分隔符与 windows 7 中的分隔符具有不同的模板。 在 Windows 10 中,它包含一个边界对象, 在 wndows 7 中有 2 个矩形的网格。

我们如何确保分隔符看起来相同? 为什么会发生这种情况?

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    为什么会发生这种情况?

    因为内置控件的默认样式在 Windows 上的不同版本和主题上看起来不同。

    我们如何确保分隔符看起来相同?

    如果您想将特定 Windows 7 主题的外观应用到在 Windows 10 上运行的应用程序,您可以将主题资源字典添加到您的 App.xaml 文件:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    

    您需要引用相应的程序集,在这种情况下为PresentationFramework.Aero.dll

    【讨论】:

    • 如果我想要 windows 10 样式怎么办?在 Windows 7 中
    • 在 Windows 7 上?然后您需要自己定义一个 Window 10 样式。您可以从默认的开始:stackoverflow.com/questions/41003094/…
    • 奇怪的是这似乎是凭空发生的。这不可能,标准样式(Aero)似乎被破坏了。
    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 2017-04-21
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-10
    相关资源
    最近更新 更多