Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to WPF and i am trying to create a WPF form and trying to call from another application . I am converting the WPF output as class libarary and calling from another Solution .

There is a .cs file which call this wpf window from code behind using below code .

C#
````
Thread thre = new thread(()=> 
{
mainwindow md = new mainwindow();
md.ShowDialog();
md.Closed+=(s,e)=> md.dispatcher.InvokeShutdown();
Dispatcher.Run()
});
thre.SetApartmentState(ApartmentState.STA);
thre.Start();```
`
I Can able to call my window and all my functionality working excel the dispachter.beginInvoke is not triggering .And i also get Application.Current =null . I am unable to go to if statement in the below code.

Method in window.cs

new Thread(()=>
{
rsult= getItemID("44");
Dispatcher.BeginInvoke( new ThreadStart(()=>{
if(rsult==0)
{}
});
}).Start();
}
````


What I have tried:

I followed the sample code which is working fine but if i copy the same code its not working in my application.
Posted
Comments
[no name] 11-Jul-22 20:03pm    
I'm not aware of any "sample code" that opens a WPF window / dialog in the manner you have shown; e.g. trying to hook up a Closed event handler "after" showing a modal dialogs; among other things.
Richard Deeming 12-Jul-22 4:03am    
ShowDialog displays the window and waits for it to close. The remainder of your code will not run until the window is closed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900