使用带有键的各种资源字典从 ResourceDictionary 获取资源
Get a Resource from a ResourceDictionary with various Resource Dictionary with a key
我需要将单个文件中的资源放入一个 ResourceDictionary 元素中,其中包含带有键
的各种 resourceDictionary
下一个代码是这样的示例:
<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" />
结果
我需要将单个文件中的资源放入一个 ResourceDictionary 元素中,其中包含带有键
的各种 resourceDictionary下一个代码是这样的示例:
<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" />
结果