当从windows窗体应用程序打开wpf窗口时,缺少图像

时间:2021-01-07 20:37:49

I am trying to open a WPF-window from a Windows Forms application. The Windows loads, and the functionality of the WPF-window is as it should be, but the images i added to some buttons in my WPF-window do not get shown. The build action property of the images has been set to "Resource". I am loading from the WinForm App with this code:

我正在尝试从Windows窗体应用程序中打开一个wpf窗口。Windows加载,WPF-window的功能应该是这样的,但是我在WPF-window中添加的一些按钮上的图像没有显示出来。映像的build action属性被设置为“Resource”。我从WinForm App中下载了以下代码:

private void button1_Click(object sender, EventArgs e)
{
    var wpfwindow = new WPF.View.MainWindow();
    wpfwindow.Show();
}

What can i do to solve the problem?

我能做什么来解决这个问题?

1 个解决方案

#1


0  

In WinForms there is no WPF System.Windows.Application active, therefore 'pack' uri prefix is not recognized and resource images referenced as 'pack://some image uri' cannot be loaded.

在WinForms中没有WPF System.Windows。应用程序处于活动状态,因此无法识别“pack”uri前缀,无法加载作为“pack://某些映像uri”引用的资源映像。

Either register uri prefix:

要么注册uri的前缀:

if (!UriParser.IsKnownScheme("pack"))
{
    UriParser.Register(new GenericUriParser
        (GenericUriParserOptions.GenericAuthority), "pack", -1);
}

or try to create an instance of Application class

或者尝试创建应用程序类的实例

#1


0  

In WinForms there is no WPF System.Windows.Application active, therefore 'pack' uri prefix is not recognized and resource images referenced as 'pack://some image uri' cannot be loaded.

在WinForms中没有WPF System.Windows。应用程序处于活动状态,因此无法识别“pack”uri前缀,无法加载作为“pack://某些映像uri”引用的资源映像。

Either register uri prefix:

要么注册uri的前缀:

if (!UriParser.IsKnownScheme("pack"))
{
    UriParser.Register(new GenericUriParser
        (GenericUriParserOptions.GenericAuthority), "pack", -1);
}

or try to create an instance of Application class

或者尝试创建应用程序类的实例