当我尝试将valueconverter从定义枚举状态结合到刷皈依的结果,我得到一个错误,在我的XAML设计:使用资源的绑定转换器
没有发现“OKStatus”资源。
该应用程序运行良好,但我无法在设计器中看到我的GUI。 我的资源是在运行时读取的color.xaml文件中定义的。 所有的代码都是相同的命名空间
我的XAML中:
的xmlns:配置= “CLR的命名空间:App.MyNamespace”
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="c:\Skins\Colors.xaml" />
<ResourceDictionary Source="c:\Skins\Common.xaml" />
</ResourceDictionary.MergedDictionaries>
<config:StatusConverter x:Key="StateConverter" />
<config:BoolConverter x:Key="BoolConverter" />
<config:BooleanConverter x:Key="BooleanConverter" />
</ResourceDictionary>
</UserControl.Resources>
和
状态
My conver之三:
[ValueConversion(typeof(bool), typeof(Brush))]
public class BoolConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
bool state = (bool)value;
FrameworkElement FrameElem = new FrameworkElement();
if (state == true)
return (FrameElem.FindResource("OKStatus") as Brush);
else
return (FrameElem.FindResource("ErrorStatus") as Brush);
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return null;
}
}
在此代码frameElem不会有我定义我猜资源的任何知识,所以我需要一种方式来获得设计时访问我的资源。 这可能吗?
我个人与Joel的解决方案一起上面,因为它似乎更少计算密集型。 TryFindResource会在我的应用程序中花费我不得不修改巨大数据网格中的项目颜色。 – Eternal21 2014-03-04 20:56:18