Passing Data From a window to the mainview(shellViewModel) using EventAggregator - WPF Caliburn.Micro
-
I have been up almost all night reading on this subject. I have my main ViewModel (ShellViewModel), when the user selects a button a new window opens for the user to type something and a file chooser to select the file to read. All I want to do is pass the Text typed in and the file path (as a string) back to the main view model for processing. I believe I understand the concept of using EventAggregator to pass an event containing the data I want from the second window to the first. My problem is all the examples are showing the main VM creating two separate VM and the data is passed between the two individual VM's. My ShellViewModel has the following method when the button is selected (I know using WindowManager in this fashion is not "best practice", but works for now:
public void LoadSchedule()
{
WindowManager windowManager = new WindowManager();
SelSchedViewModel vm = new SelSchedViewModel();
windowManager.ShowDialog(vm);
}I have added a Handle to the ShellViewModel as well as Implimented "IHandle" Handle Code in ShellViewModel:
public void Handle(ScheduleInfo message)
{
ScheduleName = message.ScheduleName;
FileInfo = message.FileLocation;
}I have created the class "SheduleInfo" to hold the data for the event
public class ScheduleInfo
{
public string ScheduleName
{
get;
private set;
}public string FileLocation { get; private set; } public ScheduleInfo(string SN, string FL) { ScheduleName = SN; FileLocation = FL; } }
SheduleName and FileLocation have been added to ShellViewModel:
public string ScheduleName
{
get { return _scheduleName; }
set {
_scheduleName = value;
NotifyOfPropertyChange(() => ScheduleName);
}
}
public string FileInfo
{
get { return _fileInfo; }
set {
_fileInfo = value;
NotifyOfPropertyChange(() => FileInfo);
}
}The second window "SelSchedViewModel" has a load button that when text is written in the text box and a file has been selected, is supposed to pass that data back and close this windows. I am stuck on how to set up the SelShedViewModel
-
I have been up almost all night reading on this subject. I have my main ViewModel (ShellViewModel), when the user selects a button a new window opens for the user to type something and a file chooser to select the file to read. All I want to do is pass the Text typed in and the file path (as a string) back to the main view model for processing. I believe I understand the concept of using EventAggregator to pass an event containing the data I want from the second window to the first. My problem is all the examples are showing the main VM creating two separate VM and the data is passed between the two individual VM's. My ShellViewModel has the following method when the button is selected (I know using WindowManager in this fashion is not "best practice", but works for now:
public void LoadSchedule()
{
WindowManager windowManager = new WindowManager();
SelSchedViewModel vm = new SelSchedViewModel();
windowManager.ShowDialog(vm);
}I have added a Handle to the ShellViewModel as well as Implimented "IHandle" Handle Code in ShellViewModel:
public void Handle(ScheduleInfo message)
{
ScheduleName = message.ScheduleName;
FileInfo = message.FileLocation;
}I have created the class "SheduleInfo" to hold the data for the event
public class ScheduleInfo
{
public string ScheduleName
{
get;
private set;
}public string FileLocation { get; private set; } public ScheduleInfo(string SN, string FL) { ScheduleName = SN; FileLocation = FL; } }
SheduleName and FileLocation have been added to ShellViewModel:
public string ScheduleName
{
get { return _scheduleName; }
set {
_scheduleName = value;
NotifyOfPropertyChange(() => ScheduleName);
}
}
public string FileInfo
{
get { return _fileInfo; }
set {
_fileInfo = value;
NotifyOfPropertyChange(() => FileInfo);
}
}The second window "SelSchedViewModel" has a load button that when text is written in the text box and a file has been selected, is supposed to pass that data back and close this windows. I am stuck on how to set up the SelShedViewModel
I do MVVM if I had no choice. My "personal" projects are allowed to "fly" and change is part of the process. What you're describing is pain for a "possible" future (employment) gain ... the 2 never coincide.
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
I do MVVM if I had no choice. My "personal" projects are allowed to "fly" and change is part of the process. What you're describing is pain for a "possible" future (employment) gain ... the 2 never coincide.
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
What I am describing is using work situations to learn. There is a chance I will be asked to work with our development/IT department on our in house application because I have been a hobby programmer and have more than 20 years experience in the companies primary focus industry. If I get offered a position in the development team, I'll jump all over it. Other than that, not sure what your post is getting at.
-
What I am describing is using work situations to learn. There is a chance I will be asked to work with our development/IT department on our in house application because I have been a hobby programmer and have more than 20 years experience in the companies primary focus industry. If I get offered a position in the development team, I'll jump all over it. Other than that, not sure what your post is getting at.
That's good ... learning MVVM in this case has a specific goal. I often see people struggling over some aspect literally "for days" because of the "rules". Most apps will live and die never needing to "switch out the UI". Spending half your time "engineering" instead of "shipping" serves no one. And you will never convince me that MVVM is a "productivity booster" for the majority. In MVVM, you're always struggling with the "plumbing", rarely the "business rules" (which is the point of IT; not "patterns").
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
That's good ... learning MVVM in this case has a specific goal. I often see people struggling over some aspect literally "for days" because of the "rules". Most apps will live and die never needing to "switch out the UI". Spending half your time "engineering" instead of "shipping" serves no one. And you will never convince me that MVVM is a "productivity booster" for the majority. In MVVM, you're always struggling with the "plumbing", rarely the "business rules" (which is the point of IT; not "patterns").
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
In a way I do agree with you, however, unless you are the top dog in a situation, you must follow others concepts. Here I have 2 issues, one I am trying to learn this concept because my company does use an MVVM framework, albeit custom fabbed. I have also learned a long time ago to learn more than one way to accomplish your goals, this provides you the ability to adapt and overcome when required. The second issue is more a personal one. I hate it when I have trouble solving something!! You Gerry, In ways I agree but I (being still an amateurs amateur, there is little I can do with changing the mind of the person who has spent the past 4 years developing, maintaining and upgrading the companies SW.
-
In a way I do agree with you, however, unless you are the top dog in a situation, you must follow others concepts. Here I have 2 issues, one I am trying to learn this concept because my company does use an MVVM framework, albeit custom fabbed. I have also learned a long time ago to learn more than one way to accomplish your goals, this provides you the ability to adapt and overcome when required. The second issue is more a personal one. I hate it when I have trouble solving something!! You Gerry, In ways I agree but I (being still an amateurs amateur, there is little I can do with changing the mind of the person who has spent the past 4 years developing, maintaining and upgrading the companies SW.
Ask them "why" they are using MVVM. (Most people can't). The answer (or lack of one) will tell you volumes about what drives the "standards" people in your organization.
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal