T
T
Tsiren Naimanov2016-08-05 11:58:28
.NET
Tsiren Naimanov, 2016-08-05 11:58:28

Best practices for opening a window in WPF?

What is the best way to open windows in WPF???
the bottom line is that I need to open 3 different windows one after the other,
for example, now I call the window like this

var propPage = new SomeWindow(IEnumerable<Properties> items);
           var openResult = propPage.ShowDialog();
                 if (openResult.HasValue && openResult.Value)
                       //DoSomething

And for example, those three in a row it turns out that you have to shit-code
var propPage1 = new SomeWindow(IEnumerable<Properties> items);
            var openResult = propPage1.ShowDialog();
            if (openResult.HasValue && openResult.Value)
            {
                var propPage2 = new SomeWindow(IEnumerable<Properties> items);
                openResult = propPage2.ShowDialog();
                if (openResult.HasValue && openResult.Value)
                {
                    var propPage3 = new SomeWindow(IEnumerable<Properties> items);
                    openResult = propPage3.ShowDialog();
                    if (openResult.HasValue && openResult.Value)
                    {
                        //DoSomething
                    }
                }
            }

As a result, I don’t know how to organize it better ...
And another question. after the ShowDialog result arrives, whether the window is disposed or only GUI-dispose occurs, because I need to pull data from the ViewModel...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rou1997, 2016-08-05
@ImmortalCAT

The code is normal, you have not seen Java, well, if you want to get rid of unnecessary block nesting, use IF-NOT-RETURN.
Nothing is removed while in use, then the garbage collector removes it.

A
AxisPod, 2016-08-09
@AxisPod

And why 3 windows, why not, for example, use the Wizard dialog.

A
Alexander Ryzhov, 2016-08-29
@RyzhovAlexandr

I recommend using a dependency container, such as Autofac, more details with examples can be found here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question