2011-03-21 5 views
0

異なるアセンブリからカスタムコンバータを実装しようとしていますが、無視されているようです。私はこれを打ち負かしてエラーを見ることができないので、XAMLの忍者が助けてくれるかもしれません。ここでは、関連するコードが...別のアセンブリからカスタムコンバータを含める

xmlns:converters="clr-namespace:Shared.Converters;assembly=Shared" 

とリソースの辞書です...ここで

<ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="pack://application:,,,/Shared;component/Styles.xaml"/> 
      <ResourceDictionary> 
       <converters:SaveStatusConverter x:Key="saveStateConverter" /> 
      </ResourceDictionary> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 

は全体のコンバータそのものです。

名前空間Shared.Converters { パブリッククラスSaveStatusConverter:IValueConverter {

public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) 
{ 

    bool? buttonState = (bool?)value; 
    Uri resourceLocater = new Uri("/Shared;component/Styles.xaml", System.UriKind.Relative); 
    ResourceDictionary resourceDictionary = (ResourceDictionary)Application.LoadComponent(resourceLocater); 
    if(buttonState == true) 
    return resourceDictionary["GreenDot"] as Style; 
    if (buttonState == false) 
    return resourceDictionary["RedDot"] as Style; 
    return resourceDictionary["GreyDot"] as Style; 

} 

public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) 
{ 
    throw new System.NotImplementedException(); 
} 

}}

そして、ここに私の実装です...

<ContentControl Style="{Binding Path=SaveState, Converter={StaticResource saveStateConverter}}"/> 

私が知っていますスタイルが動作する...それは問題ではない、私はコンバータと思うそれは事前に...

感謝し、私は問題を見ることができないが、それを呼び出すようにしようとしています方法とは何かを持っている必要があり、あまりにも結構です。

答えて

0

Errは、不平不平を言う...私は私のデフォルト状態の名前にタイプミスがあった「グレー」「グレー」ではない - とにかく - これは、これを行う方法の例も悪くないです。 :)

関連する問題