我正在尝试加载一个外部XML文件,其中包含对WPF中图像的引用.
<page>
<foreground path="/data/images/attract/slide1/foreground.png">
<background path="/data/images/attract/slide1/background.png">
</page>
Run Code Online (Sandbox Code Playgroud)
我正在解析XML并使用以下代码将每个路径属性转换为ImageSource.
string backgroundString = (string)backgroundNode.Attributes["path"].Value;
Debug.WriteLine(backgroundString); //returns "/data/images/attract/slide1/background.png"
avm.BackgroundImage = new ImageSourceConverter().ConvertFromString(backgroundString) as ImageSource;
Run Code Online (Sandbox Code Playgroud)
当我将它写入调试输出时,我正在解析的backgroundString不为null.但是,我收到以下错误.
A first chance exception of type 'System.NullReferenceException' occurred in PresentationCore.dll
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Media.ImageSourceConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.ComponentModel.TypeConverter.ConvertFromString(String text)
Run Code Online (Sandbox Code Playgroud)
有谁看到我做错了什么?任何帮助将非常感激.
谢谢,布莱恩