Reputation: 385
How to use WPF window as a messagebox? here is how I was able to get messagebox. Now I want it to return back certain value in the userControl. Any help?
Upvotes: 0
Views: 1371
Reputation: 8812
The WPF solution for these problems is the 'Page Function'.
PageFunction is a new term defined in WPF. It enables the user to navigate to a specific page and perform a task, then navigate back to the caller page with the result. It behaves just like Modal Dialogbox with the difference that PageFunction won’t be displayed as s pop-up, instead it is displayed in the same page as the caller.
It differs from the pattern of wrapping the ShowDialog in that the page is navigated to, and more importantly, it is already strongly typed within the WPF plumbing and does not require you to develop a new class to do the same thing.
There is an explanatory StackOverflow thread here...
WPF - PageFunctions. Why are they needed?
Upvotes: 1
Reputation: 29266
as @SLaks says, use the DialogReslult... if that is not enough and you are using an MVVM model, then you could use your data model: set the DataContext
of the child window to your data model instance then you can bind the contorls in your child window to any data member on your model--typically you would set the DataContext
to the DataContext
of the parent window...
protected popMyWindow()
{
MyChildWindow cw = new MyChildWindow();
cw.DataContext = this.DataContext();
// show the window...
}
Upvotes: 2
Reputation: 888167
Set the window's DialogResult
in the window itself before closing.
The value you set will be returned by ShowDialog()
If you want to return more than a bool?
, create a wrapper method that calls ShowDialog()
and returns whatever you want.
Upvotes: 1