Alias or Reference in ResourceDictionary

后端 未结 2 1824
陌清茗
陌清茗 2020-12-21 13:44

I\'m looking for a way to essentially give an item in a ResourceDictionary multiple keys. Is there a way to do this?



        
相关标签:
2条回答
  • 2020-12-21 14:27

    There is no way that I know of to do this.

    However, if your goal is multiple templates for multiple controls, you may be going at this the wrong way.

    You could have multiple resources (data templates and dynamic resources) with the same globally named key, or default key (control class type) for styles, then load a different resource dictionary file into every control/region/tab/window, during run time.

    0 讨论(0)
  • 2020-12-21 14:47

    You can pipe resources through dynamic resources (note that crappy UI designers won't like it)

    <Color x:Key="color">Red</Color>
    <DynamicResource x:Key="mycolor" ResourceKey="color"/>
    
    <Rectangle Width="100" Height="100">
        <Rectangle.Fill>
            <SolidColorBrush Color="{StaticResource color}"/>
        </Rectangle.Fill>
    </Rectangle>
    <Rectangle Width="100" Height="100">
        <Rectangle.Fill>
            <SolidColorBrush Color="{StaticResource mycolor}"/>
        </Rectangle.Fill>
    </Rectangle>
    
    0 讨论(0)
提交回复
热议问题