简体   繁体   中英

Missing images when opening a wpf window from a windows forms application

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:

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

What can i do to solve the problem?

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.

Either register uri prefix:

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

or try to create an instance of Application class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM