我有一个库,CommonLibraryWpfThemes,里面有几个Resource Dictionary XAML文件.My Themes/Generic.xml文件包含一个ResourceDictionary.MergedDictionaries声明,它将所有其他文件合并在一起.
Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/BrushDictionary.xaml" />
<ResourceDictionary
Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/TextBlockDictionary.xaml" />
<ResourceDictionary
Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/LabelDictionary.xaml" />
<ResourceDictionary
Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/ButtonDictionary.xaml" />
<ResourceDictionary
Source="/CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
在我的应用程序项目中,我引用了CommonLibraryWpfThemes,并在我的App.xaml文件中显式引用了Generic.xml.
App.xaml - 失败
<Application
x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary
Source="/CommonLibraryWpfThemes;component/Themes/Generic.xaml" />
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
这不起作用.运行我的应用程序时出现以下错误:
System.Windows.Markup.XamlParseException occurred
Message="Cannot find resource named '{_fadedOrangeBrush}'. Resource names are case sensitive. Error at object 'System.Windows.Setter' in markup file 'CommonLibraryWpfThemes;component/ResourceDictionaries/WindowDictionary.xaml' Line 18 Position 13."
Source="PresentationFramework"
LineNumber=18
LinePosition=13
Run Code Online (Sandbox Code Playgroud)
如果我直接将Generic.xaml的内容放入App.xaml,一切正常:
App.xaml - SUCCEEDS
<Application
x:Class="MyApp.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 …
Run Code Online (Sandbox Code Playgroud) 我有一个ResourceDictionary,其中包含我的应用程序中使用的控件的样式定义.
所有样式都适用于窗口中的控件...但是不应用ResourceDictionary中窗口本身的样式.
这是我的ResourceDictionary中的XAML,其中包含我要应用于窗口的样式:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:primatives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="#FF121212"></Setter>
<Setter Property="Height" Value="768"></Setter>
<Setter Property="Width" Value="1024"></Setter>
</Style>
<!-- .... -->
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的窗口的XAML(尝试使用此样式):
<Window x:Class="TryingStyles"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="TryingStyles">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/StylesDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Label1" VerticalAlignment="Top" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="56,14,0,0" Name="TextBox1" VerticalAlignment="Top" Width="120" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TabControl Height="206" HorizontalAlignment="Left" Margin="12,43,0,0" Name="TabControl1" VerticalAlignment="Top" Width="250">
<TabItem Header="TabItem1" Name="TabItem1">
<Grid></Grid>
</TabItem>
</TabControl>
<GroupBox Header="GroupBox1" Margin="268,43,12,12" Width="396"></GroupBox>
</StackPanel>
</StackPanel> …
Run Code Online (Sandbox Code Playgroud) 由于我Window
在我的应用程序中有多个s,我正在寻找一个不需要我binding
在每个上面设置的解决方案Window
.
我创建了一个ResourceDictionary
具有style
窗口背景的:
<Style TargetType="{x:Type Window}">
<Setter Property="Background" Value="AliceBlue"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
在我XAML
,我设置ResourceDictionary
:
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Templates.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
没有错误,但我的Window
颜色保持白色.
我在Visual Studio 2010 Express(C#)中创建了一个WPF应用程序,并将下面的文本添加到App.xaml中的Application.Resources.我在设计器中看到应用于窗口的样式,但是当我运行应用程序时,窗口背景为白色.
如果这是一个因素,在MacBook Pro上的BootCamp上运行Windows XP.
提前致谢,
基督教
<Style TargetType="{x:Type Window}">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="WhiteSmoke" />
<GradientStop Offset="1" Color="Silver" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="20" />
</Style>
Run Code Online (Sandbox Code Playgroud) 我正在设置App.xaml
类似Window的样式:
<Application x:Class="MusicRepo_Importer.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" StartupUri="TestMaster.xaml">
<Application.Resources>
<Style TargetType="Window">
<Setter Property="WindowStyle" Value="None"></Setter>
</Style>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
我基本上希望每个Window都将其WindowStyle的属性值设置为None(删除默认的Windows框架和边框); 但它没有用.
我在这里错过了什么?