Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改xaml中已定义资源的值?_C#_Xaml_Windows Phone 8_Windows Runtime_Windows Store Apps - Fatal编程技术网

C# 如何更改xaml中已定义资源的值?

C# 如何更改xaml中已定义资源的值?,c#,xaml,windows-phone-8,windows-runtime,windows-store-apps,C#,Xaml,Windows Phone 8,Windows Runtime,Windows Store Apps,我在xaml中有一个网格,它将资源用于其附加的弹出按钮: <Grid > <FlyoutBase.AttachedFlyout> <StaticResource ResourceKey="GridFlyout"/> </FlyoutBase.AttachedFlyout> .. other stuffs </Grid> .. 其他东西 我在页面中定义了一个资源: <Page.Res

我在xaml中有一个网格,它将资源用于其附加的弹出按钮:

<Grid >
    <FlyoutBase.AttachedFlyout>
        <StaticResource ResourceKey="GridFlyout"/>
    </FlyoutBase.AttachedFlyout>

    .. other stuffs

</Grid>

.. 其他东西
我在页面中定义了一个资源:

<Page.Resources>
    <MenuFlyout x:Key="GridFlyout">
        <MenuFlyoutItem Text="delete"/>
        <MenuFlyoutItem Text="like"/>
        <MenuFlyoutItem Text="edit"/>
    </MenuFlyout>

但在某些情况下,我希望为上述网格设置以下资源:

<Page.Resources>
    <MenuFlyout x:Key="SecondaryGridFlyout">
        <MenuFlyoutItem Text="like"/>
    </MenuFlyout>

我该怎么做?谢谢

如果您只需在代码中执行此操作,它将是最简单的(并且完全受支持的)。使用附加属性
AttachedFlyout

FlyoutBase.SetAttachedFlyout(theGrid, 
       (MenuFlyout) App.Current.Resources["SecondaryGridFlyout"]);
上例中的网格
表示要更改的网格

<Grid x:Name="theGrid">
    <FlyoutBase.AttachedFlyout>
        <StaticResource ResourceKey="GridFlyout"/>
    </FlyoutBase.AttachedFlyout>
    <!-- ... other stuff -->
</Grid>


@loop DataTemplateSelector不适用于FlyOutIn代码,这应该可以工作:
FlyoutBase.SetAttachedFlyout(网格,(MenuFlyout)App.Current.Resources[“SecondaryGridFlyout”])其中
网格
表示您要使用新弹出按钮瞄准的网格元素。@wiredparie谢谢。这就是答案。