2016-12-26 37 views
0

我的WPF應用程序的樣式有問題。 某些用戶應用具有相同屬性(字體大小,邊距,填充)的文本塊的經典寡婦主題和ActualHeight取決於使用哪些主題和實際高度。
例如,使用航空主題的FontSize = 15的TextBlock高度爲20,經典爲18.經典Windows主題和Aero中的WPF控件大小

我怎樣才能避免這種行爲?

回答

2

根據所應用的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> 

不要忘記添加一個引用到相應的程序集(Project-> Add Reference-> Assemblies-> Visual Studio中的框架),例如,如果您決定使用Aero主題,則使用PresentationFramework.Aero.dll。

Windows 7 theme for WPF?

如何真正改變在WPF系統主題:http://northhorizon.net/2010/how-to-actually-change-the-system-theme-in-wpf/