2016-07-27 8 views
1

と様々なリソース辞書とのResourceDictionaryからリソースを取得し、次のコードは、これのサンプルです:キー</p> <p>と私は様々なの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"/> 

Keyが見つからないため、上記のコードでは_Conf_Delete_instrにエラーが発生します。

ResourceDictionaryに含まれる_Conf_Delete_instrというリソースに、「構成」キーを使ってアクセスできますか?コンバータで?

ありがとうございました。

+1

は巣にあなたの他のResourceDictionarysをお試しください「MergedDictionaries」の – lokusking

+0

こんにちは。返信いただきありがとうございます。私は単一のリソースファイルが必要です。 mergeddictionarisの他のresourceDictionary要素(キー付き)を入れ子にした場合、このエラーが発生します。「キー属性は、Idictionary型のプロパティに埋め込まれたタグでのみ使用できます。ありがとう。 – Javier

答えて

0

は例を持っている:

<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" /> 

結果

Result

+0

ありがとうlokusking。完璧!返信いただきありがとうございます – Javier

関連する問題