【发布时间】:2015-01-14 15:22:49
【问题描述】:
我对此很陌生,所以也许这是一个非常简单的事情,可能是错误的......
我尝试使用样式 ResourceDictionary 但是当我尝试在我的应用程序中使用它时它不起作用。 这是目录:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<LinearGradientBrush x:Key ="DarkBackground" StartPoint ="0,0" EndPoint =" 1,1">
<GradientStop Offset="0" Color =" #FF333344"></GradientStop>
<GradientStop Offset="1" Color =" #FF666677"></GradientStop>
</LinearGradientBrush>
<LinearGradientBrush x:Key="StandardBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF3F3F3" Offset="0"/>
<GradientStop Color="#FFEBEBEB" Offset="0.5"/>
<GradientStop Color="#FFDDDDDD" Offset="0.5"/>
<GradientStop Color="#FFBBBBBB" Offset="1"/>
</LinearGradientBrush>
Application.xaml 看起来像这样:
<Application x:Class="MyApplication.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="\src\GUI\MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source ="StyleTemplates.xaml"> </ResourceDictionary>
</Application.Resources>
</Application>
主窗口中的条目:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
在我的 MainWindow 中,我想做类似的事情:
<TabItem Header="Project config" Background="{StaticResource StandardBackground}" Margin="-2,-2,2,0" IsEnabled="{Binding ToolPreference.ProjectLoaded}">
接下来我必须做什么才能在我的 MainWindow.xaml 以及所有其他可用窗口中将样式作为静态资源获取?
在我的 MainWindow.xaml 中,我现在可以在尝试此操作时看到“StandardBackground”:
<TabItem Header="Project config" Background="{StaticResource x:StandardBackground}" Margin="-2,-2,2,0" IsEnabled="{Binding ToolPreference.ProjectLoaded}">
当我添加“x:”时,我会看到一个带有 StandardBackground 和 DarkBackground 的下拉菜单。但我收到错误:(从德语翻译成英语)“资源:x:StandardBackground 无法解析”
【问题讨论】:
-
你必须像这样合并 ResourceDictionary prntscr.com/5sdssx
-
好的,我试过了,还是不行……
-
Tabitem 背景,您可以通过编辑其样式来更改。请参阅prntscr.com/5se761。