经典 Windows 主题和 Aero 中 WPF 控件的大小
Size of WPF Controls in Classic Windows Theme and Aero
我的 WPF 应用程序的样式有问题。
一些用户使用 Classic Widows 主题,具有相同属性(字体大小、边距、填充)的文本块的 ActualHeight 因使用的不同而不同。
例如,使用 aero 主题的 FontSize=15 的 TextBlock 的高度为 20,在经典中为 18。
我怎样才能避免这种行为?
内置控件的默认样式看起来会有所不同,具体取决于所应用的 Windows 主题。
如果您想避免这种情况,您可以通过将相应主题的资源字典添加到您的 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"
xmlns:local="clr-namespace:WpfApplication1"
StartupUri="MainWindow.xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
<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>
</Application>
不要忘记添加对相应程序集的引用(Visual Studio中的项目->添加引用->程序集->框架),例如PresentationFramework.Aero.dll如果您决定使用Aero 主题。
Windows 7 theme for WPF?
如何在 WPF 中实际更改系统主题: http://northhorizon.net/2010/how-to-actually-change-the-system-theme-in-wpf/
我的 WPF 应用程序的样式有问题。
一些用户使用 Classic Widows 主题,具有相同属性(字体大小、边距、填充)的文本块的 ActualHeight 因使用的不同而不同。
例如,使用 aero 主题的 FontSize=15 的 TextBlock 的高度为 20,在经典中为 18。
我怎样才能避免这种行为?
内置控件的默认样式看起来会有所不同,具体取决于所应用的 Windows 主题。
如果您想避免这种情况,您可以通过将相应主题的资源字典添加到您的 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"
xmlns:local="clr-namespace:WpfApplication1"
StartupUri="MainWindow.xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
<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>
</Application>
不要忘记添加对相应程序集的引用(Visual Studio中的项目->添加引用->程序集->框架),例如PresentationFramework.Aero.dll如果您决定使用Aero 主题。
Windows 7 theme for WPF?
如何在 WPF 中实际更改系统主题: http://northhorizon.net/2010/how-to-actually-change-the-system-theme-in-wpf/