question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for hosted in winforms

See original GitHub issue

Is your feature request related to a problem? Please describe. Given a winforms form, that has an ElementHost with a Child set to a wpf UIElement. So there is no real wpf Window, just the ElementHost holding the wpf control. When attempting to show a dialog somewhere inside the wpf control, the DialogService cannot find the owner window of the ownerViewModel and throws an exception https://github.com/FantasticFiasco/mvvm-dialogs/blob/59a356e3e35b280a5147f0ff9281ed1f11289c30/src/net/DialogService.cs#L322 while trying to set the owner: https://github.com/FantasticFiasco/mvvm-dialogs/blob/59a356e3e35b280a5147f0ff9281ed1f11289c30/src/net/DialogService.cs#L279

Describe the solution you’d like When a window of the ownerViewModel cannot be found, search for a winform e.g. with this extension method:

public static Form FindForm(this Visual element)
        {
            HwndSource wpfHandle = PresentationSource.FromVisual(element) as HwndSource;

            if (wpfHandle == null)
            {
                return null;
            }

            ElementHost elementHost = System.Windows.Forms.Control.FromChildHandle(wpfHandle.Handle) as ElementHost;
            return elementHost.FindForm();
        }

Having that form, one can now set the owner of the WindowWrapper.window:

var helper = new WindowInteropHelper(window);
helper.Owner = ownerForm.Handle;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sknauer-ndtcommented, Jan 16, 2020

That’s a justifiable decision. The problem was solved, by dropping this library, but adapting the concept und creating the view manually and propagating the dialogResult from the viewmodel manually. The ViewModel and the view could still be used at is, there were just changes about 20 lines to be made. Nevertheless, thanks for your attention

0reactions
sknauer-ndtcommented, Jan 16, 2020

Please delete: sebastian.knauer@ibgndt.demailto:sebastian.knauer@ibgndt.de

Correct address: s.knauer@ibgndt.demailto:s.knauer@ibgndt.de

Tnx.

Von: Mattias Kindborg @FantasticFiasco [mailto:notifications@github.com] Gesendet: Donnerstag, 16. Januar 2020 09:14 An: FantasticFiasco/mvvm-dialogs mvvm-dialogs@noreply.github.com Cc: sknauer-ndt sebastian.knauer@ibgndt.de; Author author@noreply.github.com Betreff: Re: [FantasticFiasco/mvvm-dialogs] Add support for hosted in winforms (#96)

Well that sounds like the perfect solution. A dependency, even to MVVM Dialogs 😀, comes with a cost. If you are able to solve your problem without this dependency, we are both better off.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/FantasticFiasco/mvvm-dialogs/issues/96?email_source=notifications&email_token=AOIYO6F3KXGLN4FBPQI35W3Q6AJOFA5CNFSM4KGRFXUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEJDFNPA#issuecomment-575035068, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOIYO6FOPF3W3VD5XWLWEJTQ6AJOFANCNFSM4KGRFXUA.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Walkthrough Create a UII Windows Forms Hosted Control
Step 1: Create a UII Windows Forms hosted control using Visual Studio · From the list of installed templates, expand Visual C#, and...
Read more >
Hosting an interactive web service in a windows form ...
So I know how to host an WCF service in a windows form application. But How do I get the service to interact...
Read more >
Embed WPF User Controls in WinForms Applications
Steps to Host WPF UserControl in Winforms · Add ElementHost Control · Creating a WPF UserControl · Editing WPF UserControl · Hosting WPF...
Read more >
Part 25 Self hosting a wcf service in winforms application
Hosting a wcf service in windows forms application is very similar to hosting it in a console application. ... Add a comment.
Read more >
Intro to Windows Forms (WinForms) in .NET 6
Windows Forms, also known as WinForms, is one of the original project types in . ... In this video, I am going to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found