获得来自各种资源字典资源字典资源一键
问题描述:
我需要有一个单一的文件资源与各种资源字典与关键获得来自各种资源字典资源字典资源一键
下一个代码资源字典元素就是这样一个样本:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/ presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib">
<ResourceDictionary x:Key="Configuration">
<sys:String x:Key="_Conf_Delete_instr">Delete instrument</sys:String>
</ResourceDictionary>
<ResourceDictionary x:Key="Report">
<sys:String x:Key="mykey2">myvalue2</sys:String>
</ResourceDictionary>
</ResourceDictionary>
I wonder if when defining the content of an element can access the ResourceDictionary indicating the key:
<Button x:Name="btnDeleteInst" Content="{DynamicResource _Conf_Delete_instr}" HorizontalContentAlignment="Center" VerticalAlignment="Top" Margin="0,23,245,0" HorizontalAlignment="Right" Height="50" MinWidth="100" VerticalContentAlignment="Center" Click="btnDeleteInstr_Click"/>
上一个代码在_Conf_Delete_instr上抛出错误,因为找不到Key
。
我如何通过“Configuration”键访问ResourceDictionary中包含的资源_Conf_Delete_instr?用转换器?
谢谢。
答
有一个例子:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Name="Configuration">
<sys:String x:Key="_Conf_Delete_instr">Delete instrument</sys:String>
</ResourceDictionary>
<ResourceDictionary x:Name="Report">
<sys:String x:Key="mykey2">myvalue2</sys:String>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
测试
<Button x:Name="btnDeleteInst" Content="{DynamicResource mykey2}" HorizontalContentAlignment="Center" VerticalAlignment="Top" Margin="0,23,245,0" HorizontalAlignment="Right" Height="50" MinWidth="100" VerticalContentAlignment="Center" />
<Button x:Name="btnDeleteInst1" Content="{DynamicResource _Conf_Delete_instr}" HorizontalContentAlignment="Center" VerticalAlignment="Top" Margin="0,23,245,0" HorizontalAlignment="Right" Height="50" MinWidth="100" VerticalContentAlignment="Center" />
结果
+0
谢谢lokusking。完善!。谢谢回复 – Javier
尝试拼图您的其他ResourceDictionarys在'MergedDictionaries'里 – lokusking
嗨。谢谢你的回复。我需要一个资源文件。如果我在mergeddictionaris中嵌套我的其他resourceDictionarys元素(带键),我有这个错误:“该键属性只能用于嵌入在类型Idictionary属性中的标签”。谢谢。 – Javier