Uwp 如何设置;BitmapIcon“;或;“路径图标”;内容来自;帆布“;存储在资源字典中?

Uwp 如何设置;BitmapIcon“;或;“路径图标”;内容来自;帆布“;存储在资源字典中?,uwp,uwp-xaml,Uwp,Uwp Xaml,如何从资源字典中存储的“画布”设置“BitmapIcon”或“PathIcon”内容 <ResourceDictionary ...> <Canvas x:Key="appbaricon" Height=77 Width=77> <Path Fill="#FF000000" Data="F1 M 25.3333,42.75C 26.5189, ..."/> </Canvas> </ResourceDiction

如何从资源字典中存储的“画布”设置“BitmapIcon”或“PathIcon”内容

<ResourceDictionary ...>
    <Canvas x:Key="appbaricon" Height=77 Width=77>
        <Path Fill="#FF000000" Data="F1 M 25.3333,42.75C 26.5189, ..."/>
    </Canvas>
</ResourceDictionary>

...

<BitmapIcon  ???Content???="{StaticResource appbaricon}">

...
有没有办法使用资源字典中的画布设置BitmapIcon的内容?例如:

<AppBarButton Label="BitmapIcon" Click="AppBarButton_Click">
    <AppBarButton.Icon>
        <BitmapIcon ???Content???="{StaticResource appbaricon}">
    </AppBarButton.Icon>
</AppBarButton>

资源可以是任何可共享的对象,例如样式、模板、笔刷和颜色。但是,控件、形状和其他
框架元素
是不可共享的,因此它们不能声明为可重用资源。有关共享的更多信息,请参阅部分

是一个不可共享的控件,不能将其作为一个资源直接使用。作为一种解决方法,我建议您创建自己的
AppBarButton
样式作为资源,并对其进行自定义。在新的
AppBarButton
样式中,您可以将
图标的默认内容替换为上面定义的
画布
,而
图标
是由名为
ContentViewbox
的样式中的
视图框
控件定义的。例如:

<Page.Resources> 
    <Style x:Key="AppBarButtonStyle1" TargetType="AppBarButton">    
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="AppBarButton">
                    <Grid x:Name="Root" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" MinWidth="{TemplateBinding MinWidth}" MaxWidth="{TemplateBinding MaxWidth}">
                        ...

                        <Grid x:Name="ContentRoot" MinHeight="{ThemeResource AppBarThemeMinHeight}"> 
                        ...
                            <Viewbox x:Name="ContentViewbox" AutomationProperties.AccessibilityView="Raw" HorizontalAlignment="Stretch" Height="20" Margin="0,14,0,4">
                                <ContentPresenter x:Name="Content"  Foreground="{TemplateBinding Foreground}" Height="20">
                                    <Canvas Height="77" Width="77">
                                        <Path Data="F1 M 16,12 20,2L 20,16 1,16" Fill="#FF000000"/>
                                    </Canvas>
                                </ContentPresenter>
                            </Viewbox>
                          ...
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">    
    <AppBarButton Style="{StaticResource AppBarButtonStyle1}" Label="PathIcon" />
</Grid>

...
...
...