【问题标题】:xaml wpf using resource in the same xaml filexaml wpf 使用同一 xaml 文件中的资源
【发布时间】:2012-05-10 02:49:50
【问题描述】:

我正在使用以下 xaml 资源:

<local:MyUIElement x:Key="MyUI" />


<ControlTemplate TargetType="{x:Type local:MyControl}" x:Key="MyXC">
    <Grid>
      ........
      ........
      <MyUI />


    </Grid>

我可以这样做吗?在同一个 xaml 文件的其他资源中直接使用资源“MyUI”。

谢谢。

【问题讨论】:

    标签: wpf xaml resources


    【解决方案1】:

    键只是一个对象元素属性。正如 Content 是 Button 的一个属性一样。所以你不能使用 代替使用

    资源存储为字典,键用于识别其中的对象。 所以在代码中你可以做这样的事情,比如说,在按钮点击时改变控制模板。

    obj = this.Resources["MyXC"] as ControlTemplate;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 2019-06-21
      相关资源
      最近更新 更多