我正在创建一个简单的WPF Gui。我试图将隐式样式应用于所有UserControls,以给它们一些默认外观 - 背景颜色和字体。这似乎适用于用户控件本身。但是,当用户控件嵌入到窗口中时,样式就是列表。
例如,这是一个用户控件:
代码:
<UserControl x:Class="NtpClient.Gui.Components.MainPanel.MainPanelView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:serverSelector="clr-namespace:NtpClient.Gui.Components.ServerSelector"
xmlns:detailsPanel="clr-namespace:NtpClient.Gui.Components.DetailsPanel"
Height="350" Width="400">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<serverSelector:ServerSelectorView Grid.Column="0" Padding="6" />
<detailsPanel:DetailsPanelView Grid.Column="1" Padding="6" />
</Grid>
</UserControl>
这是带有UserControl的窗口:
代码:
<Window x:Class="NtpClient.Gui.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mainPanel="clr-namespace:NtpClient.Gui.Components.MainPanel"
Title="Network Time Servers" Height="350" Width="400">
<mainPanel:MainPanelView Width="auto" Height="auto"/>
</Window>
Themes文件在app.xaml
中设置,如下所示:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes_CoreThemes;component/ControlStyles.xaml" />
<ResourceDictionary Source="/Themes_CoreThemes;component/BrushResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Implicit Styles -->
<Style BasedOn="{StaticResource DeepBlueButtonStyle}" TargetType="Button" />
<Style BasedOn="{StaticResource ControlStyle}" TargetType="UserControl" />
</ResourceDictionary>
的App.xaml:
<Application x:Class="NtpClient.Gui.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes_CoreThemes;component/ControlStyles.xaml" />
<ResourceDictionary Source="/Themes_CoreThemes;component/BrushResources.xaml" />
<ResourceDictionary Source="Themes/Local/Local.MSControls.Core.Implicit.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
有没有人知道造成这种情况的原因,以及我如何解决它?
答案 0 :(得分:-1)
我在某个月前就遇到了这个问题
这是因为你的xaml文件在其他dll中
我不知道为什么,但设计师并没有正确处理。
看起来像是Designer的外部问题
我只是将dll的样式移到了主项目中。