2015-01-14 61 views
-1

進出口新的這個所以也許它是一個很簡單的事情,可能是錯誤的...與林資源字典WPF樣式模板

我嘗試用一​​種風格的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> 

Entrys在主窗口:

<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" 

在我的主窗口我想做類似的事情:

<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無法解析」

+0

你要合併的ResourceDictionary這樣http://prntscr.com/5sdssx –

+0

好,我試過,但它的仍然沒有工作... – Andreas

+0

Tabitem背景,你可以通過編輯它的style.see這個http://prntscr.com/5se761改變。 –

回答

0

沒有什麼不對您的XAML。我懷疑你的StandardBackground和DarkBackground資源可以在其他控件上正常工作。在這種情況下,您的問題是TabItem的Background屬性不起作用。你需要看看TabControl的樣式來實現你想要的外觀。

要驗證你的風格是至少訪問,你可以試試下面的XAML變化:

<TabItem> 
    <TabItem.Header> 
     <TextBox Text="Project config" Background="{StaticResource StandardBackground}" /> 
    </TabItem.Header> 
</TabItem> 
+0

它在文本框上正常工作。我將看看TabContol特定的背景......非常感謝。 – Andreas

-2

嘗試

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source ="StyleTemplates.xaml"> </ResourceDictionary> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 
+0

我試過了,但它仍然不能工作,我是否可能需要在「MainWindow.xaml」中添加一些內容? – Andreas

+0

除非需要使用多個字典,否則不需要合併字典。 – RogerN

+0

@Andreas對不起,你的問題對我來說還不夠清楚。 – user2250152