WPF modaless dialog on Winforms.


D

dngchn

I need to make WPF dialog that is seperate thread from parent winform dialog.
in other words I need WPF modaless dialog of parent winforms.
For example,
There is win form dialog with just one button.
When I click the button, a new thread is started.
the thread has WPF window(So, can accept User Interface).
and this WPF window should be modaless, of course that is another thread
from win form.
Is it possible?
Please show how to do this, or any stuff link.
Thanks.
 
Ad

Advertisements

P

Peter Duniho

I need to make WPF dialog that is seperate thread from parent winform
dialog.
in other words I need WPF modaless dialog of parent winforms.

Those two statements are not necessarily equivalent. A modeless dialog
doesn't imply the dialog being created in a different thread, nor does a
dialog created in a different thread imply a modeless dialog.

The thing that's important here is that you are trying to mix
System.Windows.Forms (i.e. "Forms") with System.Windows (i.e. WPF), and
Forms and WPF each have their own message dispatch mechanisms that need to
be run in different threads.
For example,
There is win form dialog with just one button.
When I click the button, a new thread is started.
the thread has WPF window(So, can accept User Interface).

Ideally, you should use a Forms window instead of WPF for your thread's
UI. Then the threading issue simply goes away.
and this WPF window should be modaless, of course that is another thread
from win form.

See above..."modeless" doesn't imply "another thread".
Is it possible?

Yes. See the System.Windows.Threading.Dispatcher.Run() method. In your
new WPF thread, you need to create your WPF window first, call Show() on
it, and then call Dispatcher.Run(). The Run() method will not return
until the window has been closed.

At least, I'm pretty sure that's how you'd do it. You are asking a WPF
question in a C# newsgroup, when all the real WPF experts (one of which I
definitely am not) are discussing WPF topics elsewhere. :)

Pete
 
M

mp

snip

At least, I'm pretty sure that's how you'd do it. You are asking a WPF
question in a C# newsgroup, when all the real WPF experts (one of which I
definitely am not) are discussing WPF topics elsewhere. :)

Pete

Hi Pete,
I've asked a couple wpf questions recently and didn't realize they were
maybe off topic here
I don't see wpf or Presentation in list of ms newsgroups...where is better
suited to wpf questions?
somewhere i saw a reference that wpf was preferred to winforms? something
like winforms is older and wpf is replacing it as a technology...is that
true? or is there a preference for which technology to start in as a newbie
like me?
thanks
mark
 
P

Peter Duniho

I've asked a couple wpf questions recently and didn't realize they were
maybe off topic here

They're not any more off-topic than Forms questions are. That is,
technically this is a C# newsgroup and any question not specifically about
the language is off-topic, but since before I was using this newsgroup the
community has accepted general .NET questions as essentially on-topic, as
long as they at least involve C# somewhere.

The real issue is that if you are looking for expert advice, this is not
always the best newsgroup to find it. We are more than happy to try to
answer the questions, and many will be within our abilities. But for the
really tricky stuff, should you run into that, you might find you're
running into the limits of our knowledge.
I don't see wpf or Presentation in list of ms newsgroups...where is
better
suited to wpf questions?

Unfortunately, Microsoft doesn't see the value in Usenet, and has not been
making new newsgroups for newer technologies. There's a WPF forum
somewhere that Microsoft hosts, but last I saw it was web browser-based
only.

A Google search can probably turn it up for you. I don't know the URL
off-hand.
somewhere i saw a reference that wpf was preferred to winforms? something
like winforms is older and wpf is replacing it as a technology...is that
true? or is there a preference for which technology to start in as a
newbie
like me?

In terms of age of API, WPF is newer than Forms. From Microsoft's point
of view, I think they may prefer you use WPF, but I don't really know for
sure. I do suspect that WPF is getting more development resources than
Forms. I doubt we're going to see any new features in Forms at all, and
even bug fixes are "iffy". I don't know for sure the status of WPF, but
it wouldn't surprise me to see new features still show up in that API
going forward.

In that sense WPF is definitely the "preferred" technology. But, Forms is
actually a very good API, and being entirely procedural/imperative in
nature, it's a closer fit to what many programmers are accustomed to.

As for what's best for a newbie, I think that depends somewhat on what
your overall experience level is. For me, one of the greatest advantages
of Forms over WPF is that it's so much closer to the older unmanaged Win32
API that I'm already used to. It's even built on top of those unmanaged
controls I'm familiar with, so a lot of my previous experience carries
over.

If you have no previous experience with Windows programming at all, I'd
say you maybe might as well go ahead and use WPF. You'll be learning new
paradigms anyway in either case, and while WPF does add an extra layer of
declarative programming that might take a little getting used to, I don't
think it's that big a leap, and I think that going forward WPF will be
better supported in Windows/.NET than Forms. WPF is probably the better
investment for someone starting completely from scratch right now.

Pete
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top