2013-10-16 27 views
1

我有一個WPF應用程序。這是存儲在App.xaml中應用資源:如何在Generic.xaml中獲取應用程序資源

<Application.Resources> 
    <SolidColorBrush 
     x:Key="wineRedBrush" 
     Color="#B0324F" /> 
    <SolidColorBrush 
     x:Key="orangeBrush" 
     Color="#F9694B" /> 
    <SolidColorBrush 
     x:Key="lightGray" 
     Color="#D4D4D4" /> 
    <SolidColorBrush 
     x:Key="darkGray" 
     Color="#A8A8A8" /> 
</Application.Resources> 

我想從我的應用程序資源LIGHTGRAY刷Generic.xaml:

<Separator 
    Grid.Column="2" 
    Background="{StaticResource ResourceKey=wineRedBrush}" 
    VerticalAlignment="Center" 
    Margin="10,4,12,0" /> 

但資源無法找到,爲什麼呢?有可能得到它嗎?

+0

你有什麼錯誤嗎? – sexta13

+0

是的,我喜歡。錯誤:未找到資源。 –

回答

1

您是否嘗試使用DynamicResource而不是StaticResource?

<Separator 
    Grid.Column="2" 
    Background="{DynamicResource wineRedBrush}" 
    VerticalAlignment="Center" 
    Margin="10,4,12,0" /> 
+0

這是作品,謝謝。 –

相關問題