我有一个资源字典 - Styles \ StyleDic1,它有一个Flyout作为其中一个资源
我把它包含在我的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}"/>
但它不起作用。我做错了什么?
更新
以下是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 :(得分:0)
问题是你在资源字典中没有资源字典,你需要将它们合并到一个字典中
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="View/Templates.xaml"/>
<ResourceDictionary Source="View/Images.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
答案 1 :(得分: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>