我有一个 WPF .Net 4.0 应用程序,它在 WinPE 4.0 下运行得很好,直到最近。我添加了如下所示的代码,它在 WinPE 4.0 下运行时破坏了应用程序。请注意,该应用程序在 Windows 7 x64 和 Windows 2012 下仍然可以正常运行。
[ValueConversion(typeof(string), typeof(bool))]
public class HeaderToImageConverter : IValueConverter
{
public static HeaderToImageConverter Instance =
new HeaderToImageConverter();
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if ((value as string).Contains("corp.com"))
{
Uri uri = new Uri
("pack://application:,,,/Images/DeployWiz_Network.png");
BitmapImage source = new BitmapImage();
source.BeginInit();
source.UriSource = uri;
source.DecodePixelHeight = 40;
source.EndInit();
return source;
}
else
{
Uri uri = new Uri
("pack://application:,,,/Images/ou2.png");
BitmapImage source = new BitmapImage();
source.BeginInit();
source.UriSource = uri;
source.DecodePixelHeight = 20;
source.EndInit();
return source;
}
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotSupportedException("Cannot convert back");
}
}
此代码允许我根据树视图项的内容在树视图控件中使用不同的图像。
在 WinPE 下运行时,出现以下异常:
因此,我将丢失的 .DLL 与 .exe 放在同一个文件夹中,然后我得到了这个异常:
.dll 有什么奇怪的地方不能在 WinPE 中工作吗?除了 WPF 中的 BitmapImage 之外,我还可以使用任何其他类来实现我的目标并避免这个 .dll 吗?BitmapImage 甚至是需要这个 .dll 的类吗?我认为这是因为它是我添加的唯一破坏我的应用程序的新代码。