Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Passing Data From a window to the mainview(shellViewModel) using EventAggregator - WPF Caliburn.Micro

Passing Data From a window to the mainview(shellViewModel) using EventAggregator - WPF Caliburn.Micro

Scheduled Pinned Locked Moved WPF
helpcsharpwpftutorialdiscussion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dwayne Barsotta
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • D Dwayne Barsotta

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • L Lost User

        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

        D Offline
        D Offline
        Dwayne Barsotta
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • D Dwayne Barsotta

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • L Lost User

            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

            D Offline
            D Offline
            Dwayne Barsotta
            wrote on last edited by
            #5

            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.

            L 1 Reply Last reply
            0
            • D Dwayne Barsotta

              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.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups