如何更改XAML定义资源的价值? [英] How to change value of a defined resource in xaml?

查看:103
本文介绍了如何更改XAML定义资源的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XAML中的网格,它使用弹出附着其资源:

I have a grid in the xaml which uses a resource for its attached flyout:

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

    .. other stuffs

</Grid>

和我在页面定义的资源:

and I have a defined resource in the page:

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

在某些情况下我想设置为上述网格下面的资源,但b
$ b

But in some conditions I want to set the following resource for the above grid:

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



我怎样才能做到这一点?谢谢

How can I do that? thanks

推荐答案

这是最简单的(和完全支持),如果你只是这样做的代码。使用附加属性 AttachedFlyout

It's easiest (and fully supported) if you just do this in code. Using the attached property AttachedFlyout:

FlyoutBase.SetAttachedFlyout(theGrid, 
       (MenuFlyout) App.Current.Resources["SecondaryGridFlyout"]);



theGrid 中的例子代表了电网要改变。

theGrid in the example above represents the Grid you want to change.

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

这篇关于如何更改XAML定义资源的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆