我真的很惊讶,这个问题似乎没有被问到…如果有,但我只是找不到,道歉.

好的,所以我的工作电脑刚刚从Windows 7升级到Windows 8.对于我的绝对恐怖,我的WPF应用程序看起来不同的几种方式…不同的,我的意思是更糟糕,更糟糕的是,控件没有正确排列等.这是一个例子:

Windows 7的:

Windows 8:

Windows 8问题(仅从此图像):

>标题栏错误,包括按钮(最小化,关闭等)
>标题栏中的字体大小错误
>标题中的Wright FontWeight(Windows 7 SemiBold设置= Windows 8粗体设置)
>标题栏中的图标(或文字)不对齐
标题栏中的图标非常模糊
>错误的填充和/或边距设置间隔左边的项目
>错误的填充和/或边距设置减少文本框高度在右边
>左侧的项目的“隐藏”默认选择颜色不再隐藏
>回到前面复选框勾选
>某些按钮上的图像非常模糊

所以我的问题是这样的:

为什么WPF应用程序在Windows 7和Windows 8之间看起来不一样,可以修复吗?

为了澄清这一点,我没有在两个操作系统上WPF之间的差异列表.上面列出的各个点也没有修复.我想让某人解释为什么这些UI看起来不同,例如.造成这些差异是什么我也听说过WPF中的一些系统设置,这将使我能够让PC将应用程序呈现在Windows 7上,但我不知道这是多么真实.

UPDATE>>>>

正如@AndrasSebö所说,有一个名为Windows 7 theme for WPF?的StackOverflow问题,它修复了Windows XP的类似问题.不幸的是,它似乎没有对Windows 8有任何影响.有没有任何微软的用户实际上知道实现什么差异导致这个问题?还是任何人?

UPDATE 2>>>>

好的,所以经过一些更多的测试,我开始认为这个问题与Windows主题无关.使用@ Gusdor的答案中提供的代码,我尝试将主题更改为Aero,没有明显的区别…让我想到了.然后我将其更改为Luna来测试该代码,并且它的工作.

通过“工作”,我的意思是Windows主题改变了,但UI控制,或更准确地说,不正确的填充和保证金保留.然后,我尝试使用@AndrasSebö提到的XAML方法将主题更改为Luna,同样的事情发生了… ScrollBars看起来不同,所以我可以看到主题已经改变,但问题依然存在.

所以现在我认为这可能与这个事实有关,这是一个全新的电脑,我正在努力…可能有一些dll或设置,我需要安装?我真的只是猜测这里 – 我将整个Microsoft .NET Framework安装到4.5.1版本,就像我在Windows 8.1上一样.

这是一个绝对的噩梦,因为我没有时间去修复这个大型应用程序中的每个视图.如果可以的话请帮忙.

好的,不幸的是,没有快速解决这个问题.如果您处于类似情况,并且此处提供的答案也不适用于您,那么这里是为了使Windows 8上的UI显示与Windows上的UI相同的手动需要进行的更改的摘要7.

TextBox:需要将填充添加到默认样式:

<Setter Property="Padding" Value="1.5,2" />

ListBoxItem:需要提供新的ControlTemplate来隐藏选择和鼠标在背景颜色上:

<Style x:Key="DefaultListBoxItem" targettype="{x:Type ListBoxItem}">
    <Setter Property="Padding" Value="0" />
    <Setter Property="Margin" Value="2,1,0" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Top" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="ListBoxItem">
                <Grid Background="{TemplateBinding Background}">
                    <visualstatemanager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="normal" />
                            <VisualState x:Name="MouSEOver" />
                            <VisualState x:Name="disabled">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="contentPresenter" Storyboard.TargetProperty="Opacity" Duration="0" To=".55" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualState x:Name="Unselected" />
                            <VisualState x:Name="Selected" /> 
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="Focusstates">
                            <VisualState x:Name="Focused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Visibility" Duration="0">
                                        <discreteObjectKeyFrame KeyTime="0">
                                            <discreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </discreteObjectKeyFrame.Value>
                                        </discreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unfocused"/>
                        </VisualStateGroup>
                    </visualstatemanager.VisualStateGroups>
                    <ContentPresenter x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}"/>
                    <Rectangle x:Name="FocusVisualElement" Fill="{x:Null}" stroke="{x:Null}" strokeThickness="0" Visibility="Collapsed" RadiusX="1" RadiusY="1" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

ComboBoxItem:需要提供新的ControlTemplate来更改选择和鼠标在背景颜色上:

<Style x:Key="{x:Type ComboBoxItem}" targettype="{x:Type ComboBoxItem}">
    <Setter Property="SnapsToDevicePixels" Value="true" />
    <Setter Property="OverridesDefaultStyle" Value="true" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type ComboBoxItem}">
                <Border x:Name="Border" Padding="2" SnapsToDevicePixels="true" Background="Transparent">
                    <visualstatemanager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="normal" />
                            <VisualState x:Name="MouSEOver">
                                <Storyboard>
                                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                        <EasingColorKeyFrame KeyTime="0" Value="#FF47484C" /> <!-- Background mouse over colour -->
                                    </ColorAnimationUsingKeyFrames>
                                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
                                        <EasingColorKeyFrame KeyTime="0" Value="White" /> <!-- Foreground mouse over colour -->
                                    </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="disabled" />
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualState x:Name="Unselected" />
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                        <EasingColorKeyFrame KeyTime="0" Value="#FF47484C" /> <!-- Background selection colour -->
                                    </ColorAnimationUsingKeyFrames>
                                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
                                        <EasingColorKeyFrame KeyTime="0" Value="White" /> <!-- Foreground selection colour -->
                                    </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="SelectedUnfocused">
                                <Storyboard>
                                    <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                        <EasingColorKeyFrame KeyTime="0" Value="Red" />
                                    </ColorAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </visualstatemanager.VisualStateGroups>
                    <ContentPresenter />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

CheckBox:需要提供新的ControlTemplate,以便在Bullet位于内容右侧时停止勾选.(感谢Fredrik对Stack Overflow上的Default ControlTemplate for CheckBox问题的回答:

<SolidColorBrush x:Key="CheckBoxFillnormal" Color="#F4F4F4" />
<SolidColorBrush x:Key="CheckBoxstroke" Color="#8E8F8F" />
<Style x:Key="EmptyCheckBoxFocusVisual">
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>
                <Rectangle Margin="1" SnapsToDevicePixels="true" stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" strokeThickness="1" strokeDashArray="1 2" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="CheckRadioFocusVisual">
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>
                <Rectangle Margin="14,0" SnapsToDevicePixels="true" stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" strokeThickness="1" strokeDashArray="1 2" />
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
<Style x:Key="{x:Type CheckBox}" targettype="{x:Type CheckBox}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="Background" Value="{StaticResource CheckBoxFillnormal}"/>
    <Setter Property="BorderBrush" Value="{StaticResource CheckBoxstroke}"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource EmptyCheckBoxFocusVisual}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type CheckBox}">
                <BulletDecorator Background="Transparent" SnapsToDevicePixels="true">
                    <BulletDecorator.Bullet>
                        <Aero:BulletChrome BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" IsChecked="{TemplateBinding IsChecked}" RenderMouSEOver="{TemplateBinding IsMouSEOver}" Renderpressed="{TemplateBinding Ispressed}"/>
                    </BulletDecorator.Bullet>
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </BulletDecorator>
                <ControlTemplate.Triggers>
                    <Trigger Property="HasContent" Value="true">
                        <Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
                        <Setter Property="Padding" Value="4,0"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

删除可怕的标题栏并显示默认的Windows 8一个:需要升级到.NET 4.5,并使用附带的System.Windows.Controls.Ribbon命名空间库,而不是以前使用的单独的“Microsoft Ribbon for WPF”(RibbonControlsLibrary)dll .

不幸的是,我从来没有发现如何在Windows 8上重现FontWeight属性的SemiBold设置.如果有人知道如何做到这一点,请让我知道.

总而言之,Windows 8的转变一直是一个痛苦而令人不安的经历.我希望这个信息能够帮助别人稍微痛苦一点.

为什么WPF应用程序在Windows 7和Windows 8之间看起来不一样,可以修复吗?的更多相关文章

  1. HTML5自定义视频播放器源码

    这篇文章主要介绍了HTML5自定义视频播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  2. HTML5自定义mp3播放器源码

    这篇文章主要介绍了HTML5自定义mp3播放器源码,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  3. html5自定义video标签的海报与播放按钮功能

    这篇文章主要介绍了html5自定义video标签的海报与播放按钮功能,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下

  4. CSS中实现动画效果-附案例

    这篇文章主要介绍了 CSS中实现动画效果并附上案例代码及实现效果,就是CSS动画样式处理,动画声明需要使用@keyframes name,后面的name是人为定义的动画名称,下面我们来看看文章的具体实现内容吧,需要的小伙伴可以参考一下

  5. h5页面背景图很长要有滚动条滑动效果的实现

    这篇文章主要介绍了h5页面背景图很长要有滚动条滑动效果的实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  6. html5借用repeating-linear-gradient实现一把刻度尺(ruler)

    这篇文章主要介绍了html5借用repeating-linear-gradient实现一把刻度尺,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  7. 如何在Canvas中添加事件的方法示例

    这篇文章主要介绍了如何在Canvas中添加事件的方法示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  8. HTML5自定义元素播放焦点图动画的实现

    这篇文章主要介绍了HTML5自定义元素播放焦点图动画的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

  9. 有关HTML5页面在iPhoneX适配问题

    这篇文章主要介绍了有关HTML5页面在iPhoneX适配问题,需要的朋友可以参考下

  10. html5简介及新增功能介绍

    这篇文章主要介绍了html5简介及新增功能介绍,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

随机推荐

  1. static – 在页面之间共享数据的最佳实践

    我想知道在UWP的页面之间发送像’selectedItem’等变量的最佳做法是什么?创建一个每个页面都知道的静态全局变量类是一个好主意吗?

  2. .net – 为Windows窗体控件提供百分比宽度/高度

    WindowsForm开发的新手,但在Web开发方面经验丰富.有没有办法为Windows窗体控件指定百分比宽度/高度,以便在用户调整窗口大小时扩展/缩小?当窗口调整大小时,可以编写代码来改变控件的宽度/高度,但我希望有更好的方法,比如在HTML/CSS中.在那儿?

  3. 使用Windows Azure查询表存储数据

    我需要使用特定帐户吗?>将应用程序部署到Azure服务后,如何查询数据?GoogleAppEngine有一个数据查看器/查询工具,Azure有类似的东西吗?>您可以看到的sqlExpressintance仅在开发结构中,并且一旦您表示没有等效,所以请小心使用它.>您可以尝试使用Linqpad查询表格.看看JamieThomson的thispost.

  4. windows – SetupDiGetClassDevs是否与文档中的设备实例ID一起使用?

    有没有更好的方法可以使用DBT_DEVICEARRIVAL事件中的数据获取设备的更多信息?您似乎必须指定DIGCF_ALLCLASSES标志以查找与给定设备实例ID匹配的所有类,或者指定ClassGuid并使用DIGCF_DEFAULT标志.这对我有用:带输出:

  5. Windows Live ID是OpenID提供商吗?

    不,WindowsLiveID不是OpenID提供商.他们使用专有协议.自从他们的“测试版”期结束以来,他们从未宣布计划继续它.

  6. 如果我在代码中进行了更改,是否需要重新安装Windows服务?

    我写了一个Windows服务并安装它.现在我对代码进行了一些更改并重新构建了解决方案.我还应该重新安装服务吗?不,只需停止它,替换文件,然后重新启动它.

  7. 带有双引号的字符串回显使用Windows批处理输出文件

    我正在尝试使用Windows批处理文件重写配置文件.我循环遍历文件的行并查找我想要用指定的新行替换的行.我有一个’函数’将行写入文件问题是%Text%是一个嵌入双引号的字符串.然后失败了.可能还有其他角色也会导致失败.如何才能使用配置文件中的所有文本?尝试将所有“在文本中替换为^”.^是转义字符,因此“将被视为常规字符你可以尝试以下方法:其他可能导致错误的字符是:

  8. .net – 将控制台应用程序转换为服务?

    我正在寻找不同的优势/劣势,将我们长期使用的控制台应用程序转换为Windows服务.我们为ActiveMQ使用了一个叫做java服务包装器的东西,我相信人们告诉我你可以用它包装任何东西.这并不是说你应该用它包装任何东西;我们遇到了这个问题.控制台应用程序是一个.NET控制台应用程序,默认情况下会将大量信息记录到控制台,尽管这是可配置的.任何推荐?我们应该在VisualStudio中将其重建为服务吗?我使用“-install”/“-uninstall”开关执行此操作.例如,seehere.

  9. windows – 捕获外部程序的STDOUT和STDERR *同时*它正在执行(Ruby)

    哦,我在Windows上:-(实际上,它比我想象的要简单,这看起来很完美:…是的,它适用于Windows!

  10. windows – 当我试图批量打印变量时,为什么我得到“Echo is on”

    我想要执行一个简单的批处理文件脚本:当我在XP中运行时,它给了我预期的输出,但是当我在Vista或Windows7中运行它时,我在尝试打印值时得到“EchoisOn”.以下是程序的输出:摆脱集合表达式中的空格.等号(=)的两侧可以并且应该没有空格BTW:我通常在@echo关闭的情况下启动所有批处理文件,并以@echo结束它们,所以我可以避免将代码与批处理文件的输出混合.它只是使您的批处理文件输出更好,更清洁.

返回
顶部