Forums » Questions and answers »
Showing a WPF dialog from the Player
Added by Subeesh Basheer over 1 year ago
Hi, I'm trying to show a WPF dialog window when a user triggers it by clicking a primitive in the virtual world. It's currently set as as follows:
<Primitive Name="box" Type="Box" Complexity="VeryLow" Position="-0.8788992,1,2.156633" Size="1,1,1">
...
<Trigger Event="MouseClick" Target="MouseEventHandler" />
</Primitive>
triggers the following lua script:
function main(obj, args)
testpluginupload:TestShowWPFForm()
end
The c# code in the plugin creates a new thread that invokes another method which in turn shows the WPF window.
public void TestShowWPFForm() {
ThreadStart ts = new ThreadStart(showForm);
Thread t = ThreadFactory.CreateThread(ts);
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}
public void showForm() {
WpfApplication1.MainWindow mw = new WpfApplication1.MainWindow();
mw.ShowDialog();
}
The code above works with a WinForms window, but when a WPF window is used, the Player crashes. Is there any other way I could show a WPF dialog from the Player?
Thanks for any help on this!
testrnp.imml - The IMML file as currently used. (1.2 kB)
Replies (1)
RE: Showing a WPF dialog from the Player
-
Added by Craig Presti over 1 year ago
I did similar when writing a plugin that hosts WPF based dialogs (Plugin.Dialog), it was a little trickier than the winforms approach to get right, although I've found a pattern that works reasonably well (apart from when the dialogs need to be TopMost and the Player is in fullscreen mode).
See the attached DialogBase and TextEntryController classes for some hints on how to go about it.
TextEntryController.cs (1.1 kB)
DialogBase.cs (2.8 kB)
(1-1/1)