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}}"/>
我知道樣式工作...這不是一個問題,我認爲轉換器是也沒關係,它必須是與我試圖把它雖然我不能看到問題的方式......
在此先感謝。