开发者

Including a custom converter from a different assembly

I am trying implement a custom converter from a different assembly but it seems to be getting ignored. I have beat this to death and can't see my error so maybe some XAML ninja could help out. Here is the relevant code...

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

And the resource dictionary...

<ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Shared;component/Styles.xaml"/>
            <ResourceDictionary>
                <converters:SaveStatusConverter x:Key="saveStateConverter" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionarie开发者_JAVA技巧s>
    </ResourceDictionary>

Here is the entire converter itself.

namespace Shared.Converters { public class 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();
}

} }

And here is my implementation...

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

I know the styles work... that isn't an issue, I think the converter is fine too, it must have something to do with the way I am trying to call it although I can't see the issue...

Thanks in advance.


Err, grumble grumble... I had a typo in the name of my default state "gray" not "grey" - Anyway - this is not a too bad example of how to do this. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜