注意:我有一个ResourceDictionary和WPF窗口(我的视图)和ViewModel,都在 WinForms 应用程序中声明。因此我没有App.xaml。
我声明了以下转换器:
Public Class DebugConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Return value
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Return value
End Function
End Class
然后我尝试在运行时加载ResourceDictionary(我将构建操作指定为Resource而不是Page):
m_rdGridDictionary = New ResourceDictionary()
m_rdGridDictionary.Source = New Uri("pack://application:,,,/WPF/Helpers/GridResourceDictionary.xaml")
在ResourceDictionary中,我将其声明为:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cnv="clr-namespace:Positron.Cad.WindowGUI.WPFConverters">
<cnv:DebugConverter x:Key="DebugConverter"/>
</ResourceDictionary>
但是当我尝试加载ResourceDictionary时,它找不到转换器:
有人知道这种情况有什么问题吗?它们都存在于相同的名称空间中,因此不应该是问题。
答案 0 :(得分:2)
解决! Build操作必须是Page而不是Resource。