2017-02-20 131 views
1

引用我有一個資源字典 - 樣式\ StyleDic1,這有一個彈出按鈕作爲訪問資源聲明中資源字典中的App.xaml

我把它在我的App.xaml文件,像這樣它的資源之一:

<Application 
    ... 
    ...> 
<Application.Resources> 
    ... 

    <ResourceDictionary Source="Styles\StyleDictionary1.xaml" x:Key="StyleDic1"/> 

</Application.Resources> 
</Application> 

我有AppBarButton另一個文件TimeTC.xaml,我想使用彈出的資源就可以了,所以它試圖這樣

<AppBarButton Icon="Edit" Label="Edit" ... Flyout="{StaticResource ResourceKey=EditFlyout}"/> 

但它不工作。我究竟做錯了什麼?

UPDATE

這裏有App.xaml中

<Application 
    x:Class="SabinusUWP.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:SabinusUWP" 
    RequestedTheme="Light"> 
    <Application.Resources> 
     <x:Int32 x:Key="TimeFormat">24</x:Int32> 
     <Color x:Key="grayish">#99CBCBCB</Color> 
     <Color x:Key="deepgray">#99AAAAAA</Color> 
     <Color x:Key="black">#FF000000</Color> 
     <Color x:Key="sleepblack">#FF414141</Color> 
     <Color x:Key="bluegray">#FFE3F3F2</Color> 
     <Color x:Key="transparent">#00E3F3F2</Color> 
     <Color x:Key="green">#CC2B9B2B</Color> 
     <Color x:Key="hoverGreen">#CC3BC53B</Color> 
     <SolidColorBrush x:Key="AppBarBtnFBrush" Color="{StaticResource black}"/> 
     <SolidColorBrush x:Key="AppBarBBrush" Color="{StaticResource grayish}"/> 
     <SolidColorBrush x:Key="FolderPressedBrush" Color="{StaticResource deepgray}"/> 
     <SolidColorBrush x:Key="GridBBrush" Color="{StaticResource transparent}"/> 
     <SolidColorBrush x:Key="TimeTHeadBtn" Color="{StaticResource transparent}"/> 
     <SolidColorBrush x:Key="TimeTBodyBtn" Color="{StaticResource green}"/> 
     <SolidColorBrush x:Key="TimeTBodyHoverBtn" Color="{StaticResource hoverGreen}"/> 
     <SolidColorBrush x:Name="TimeTBodySleepBtn" x:Key="TimeTBodySleepBtn" Color="{StaticResource sleepblack}"/> 
    <ResourceDictionary Source="Styles\StyleDictionary1.xaml" x:Key="StyleDic1"/> 

</Application.Resources> 

的全部內容,這裏是StyleDictionary1.xaml

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:SabinusUWP.Styles"> 

    <!--Bottom Appbar EditFlyout --> 

    <Flyout x:Name="EditFlyout" x:Key="EditFlyout" 
      Placement="Bottom"> 
     <Grid Background="White" 
       Height="150" 
       Width="100" 
       CanDrag="True"> 
      <StackPanel Background="White" 
         x:Name="panel" 
         Orientation="Vertical" 
         Height="150" 
         Width="100"> 
       <Button Content="12 hour" 
         Click="_12hour" 
         Height="50" 
         Width="100" 
         Background="{StaticResource AppBarBBrush}" /> 
       <Button Content="24 hour" 
         Click="_24hour" 
         Height="50" 
         Width="100" 
         Background="{StaticResource AppBarBBrush}" /> 
      </StackPanel> 
     </Grid> 
    </Flyout> 
</ResourceDictionary> 
+0

很抱歉,如果我沒有正確地傳遞信息,第二文件(TimeTC.xaml)不是資源字典,它是一個頁面。 –

+0

您可以發佈App.xaml.cs文件中的元素的* full *內容以及Styles \ StyleDic1.xaml的內容嗎? – mm8

回答

0

問題是你不能有一個資源詞典在資源詞典中,你需要將它們合併成一個詞典

<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="View/Templates.xaml"/> 
      <ResourceDictionary Source="View/Images.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 

    </ResourceDictionary> 
</Application.Resources> 
0

您可以添加合併dictinory到款式N多添加到您的應用程序

示例代碼:

<Application x:Class="WpfApplication2.App" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Startup="App_OnStartup" 
     StartupUri="MainWindow.xaml"> 
<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Style.xaml"/> 
      <ResourceDictionary Source="Style1.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources>