【发布时间】:2011-03-22 00:49:01
【问题描述】:
我正在尝试从不同的程序集实现自定义转换器,但它似乎被忽略了。我已经把它打死了,看不到我的错误,所以也许一些 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}}"/>
我知道样式有效...这不是问题,我认为转换器也很好,它必须与我尝试调用它的方式有关,尽管我看不到问题。 ..
提前致谢。
【问题讨论】: