Home > Net >  WPF MVVM management view and viewmodel problems
WPF MVVM management view and viewmodel problems

Time:10-16

have been writing the Java before, after the company recently a c # project, are implemented with WPF, I built a MVVM framework, and integrate the MaterialDesign,

Now I encountered the problem is that if there are multiple current window, if I want to create a new window in the viewmodel, and control in addition to the new window all Windows closed, only by creating a viewmodel passes the current viewmodel implementation, so the code dependence is too strong, special mess, if carried by value,

Excuse me, is there any way to realize unified management was carried out on the window the viewmodel and view of public methods?

For c # I know still shallow, what we say the wrong you correct,

CodePudding user response:

The great god can only way ah, searched a lot of can't find the answer,

CodePudding user response:

reference 1st floor qq_43004166 response:
, the great god can only way ah, searched a lot of also can not find the answer,

Public class called
 
Public class WindowHelper
{
Public static readonly DependencyProperty DialogResultProperty=DependencyProperty. RegisterAttached (
"DialogResult typeof (bool? The typeof (WindowHelper), new PropertyMetadata (DialogResultChanged));
Private static void DialogResultChanged (DependencyObject DependencyObject, DependencyPropertyChangedEventArgs e)
{
If (dependencyObject is Window Window & amp; & E.N ewValue!=null)
{
Window. The DialogResult=e.N ewValue as bool? ;
}
}
}


Front desk xaml bindings
 WindowHelper. DialogResult="{Binding DialogResult, Mode=OneWay}" 


Create a new DialogResult property in the viewmodel, DialogResult=true; Is closed,

CodePudding user response:

You still do Java, c # doesn't suit you

CodePudding user response:

Write a helper to view and viewmodel save
Then as you do

CodePudding user response:

Windows???

Window, and why should you tube you tube window depend on strong,

Behind, it is said, I need to change the window, the window is not what I want, the window according to A + B + C to choose, brother, do you think this depend on the strength is not strong,

Really want to write, please delegate, let outsiders STH over and over again, you don't mind,

CodePudding user response:

Recommend between vm and vm through the message center to communicate with each other
  •  Tags:  
  • C#
  • Related