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. Design and Architecture
  4. WPF App Design Thoughts

WPF App Design Thoughts

Scheduled Pinned Locked Moved Design and Architecture
questioncsharpwpfcomdesign
19 Posts 4 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.
  • K Kevin Marois

    I'm sort of there on this... Can you show me how in the MainWindowViewModel this code is used? For example, if the user selects Show All Customers, how does the template above get used/loaded in the MainWindowViewModel? I saw in his article where it says "The MainWindowResources.xaml file has a Resource­Dictionary. That dictionary is added to the main window's resource hierarchy, which means that the resources it contains are in the window's resource scope. When a tab item's content is set to a ViewModel object, a typed DataTemplate from this dictionary supplies a view (that is, a user control) to render it" So the Content is set to a VM, not a View?

    If it's not broken, fix it until it is

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #9

    That's correct. The appropriate DataTemplate is picked because it matches the ViewModel. In other words, it looks at the DataType to pick up the appropriate DataTemplate.

    *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

    "Mind bleach! Send me mind bleach!" - Nagy Vilmos

    CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

    I K 2 Replies Last reply
    0
    • P Pete OHanlon

      That's correct. The appropriate DataTemplate is picked because it matches the ViewModel. In other words, it looks at the DataType to pick up the appropriate DataTemplate.

      *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

      "Mind bleach! Send me mind bleach!" - Nagy Vilmos

      CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

      I Offline
      I Offline
      Ian Shlasko
      wrote on last edited by
      #10

      Ah, right, forgot about just setting the DataTemplates based on VM type... Much cleaner than a DataTemplateSelector... So, what Pete said :)

      Proud to have finally moved to the A-Ark. Which one are you in?
      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

      P 1 Reply Last reply
      0
      • I Ian Shlasko

        Ah, right, forgot about just setting the DataTemplates based on VM type... Much cleaner than a DataTemplateSelector... So, what Pete said :)

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #11

        Hey, you and me are in this WPF thing together bro. ;)

        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

        CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

        I 1 Reply Last reply
        0
        • P Pete OHanlon

          Hey, you and me are in this WPF thing together bro. ;)

          *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #12

          In it? Man, I'm up to my neck in it, and it's great :) Granted, I tend to stray from proper MVVM now and then, but I gotta say, WPF enables some nice-looking and stable interfaces... Never going back to WinForms :)

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          1 Reply Last reply
          0
          • P Pete OHanlon

            That's correct. The appropriate DataTemplate is picked because it matches the ViewModel. In other words, it looks at the DataType to pick up the appropriate DataTemplate.

            *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

            K Offline
            K Offline
            Kevin Marois
            wrote on last edited by
            #13

            So I'm assuming that the VM is bound to the view automatically?

            If it's not broken, fix it until it is

            I 1 Reply Last reply
            0
            • K Kevin Marois

              So I'm assuming that the VM is bound to the view automatically?

              If it's not broken, fix it until it is

              I Offline
              I Offline
              Ian Shlasko
              wrote on last edited by
              #14

              Ideally, you don't want to change the DataContext property from code. The usual method is to set the entire window to a ViewModel, and each section can have its DataContext bound to a property on that ViewModel. MainWindow --> DataContext = MainWindowVIewModel ContentFrame --> DataContext bound to ContentModel property (on MainWindowViewModel) HelpFrame --> DataContext bound to HelpModel property (on MainWindowViewModel) That way, when you change the content, all you do is change, in this example, the ContentModel property. Since the GUI control is hooked up with databinding, it'll automatically grab the new data, and switch to the proper DataTemplate. So in short, you want to set the uppermost DataContext property once on window load, then operate exclusively through ViewModel properties.

              Proud to have finally moved to the A-Ark. Which one are you in?
              Author of the Guardians Saga (Sci-Fi/Fantasy novels)

              K 1 Reply Last reply
              0
              • I Ian Shlasko

                Ideally, you don't want to change the DataContext property from code. The usual method is to set the entire window to a ViewModel, and each section can have its DataContext bound to a property on that ViewModel. MainWindow --> DataContext = MainWindowVIewModel ContentFrame --> DataContext bound to ContentModel property (on MainWindowViewModel) HelpFrame --> DataContext bound to HelpModel property (on MainWindowViewModel) That way, when you change the content, all you do is change, in this example, the ContentModel property. Since the GUI control is hooked up with databinding, it'll automatically grab the new data, and switch to the proper DataTemplate. So in short, you want to set the uppermost DataContext property once on window load, then operate exclusively through ViewModel properties.

                Proud to have finally moved to the A-Ark. Which one are you in?
                Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                K Offline
                K Offline
                Kevin Marois
                wrote on last edited by
                #15

                I understand that, but Pete pointed me to this[^], and I'm wondering where or how in this design is the data context set? So, if the content area is defined like this

                In the MainWindowViewModel I would then set the MainContent property to the MainContentViewModel. How does the MainContentViewModel.DataContext get set. It won't know about the MainWindowViewModel. Unless I'm missing something?

                If it's not broken, fix it until it is

                I 1 Reply Last reply
                0
                • K Kevin Marois

                  I understand that, but Pete pointed me to this[^], and I'm wondering where or how in this design is the data context set? So, if the content area is defined like this

                  In the MainWindowViewModel I would then set the MainContent property to the MainContentViewModel. How does the MainContentViewModel.DataContext get set. It won't know about the MainWindowViewModel. Unless I'm missing something?

                  If it's not broken, fix it until it is

                  I Offline
                  I Offline
                  Ian Shlasko
                  wrote on last edited by
                  #16

                  DataContext is inherited, so when the window itself is created, set its DataContext to a root ViewModel class. Then when you use the code you just posted, it would bind to the "MainContent" property of that ViewModel, which would be your MainContentViewModel (Or whatever you decide to call it). The initial DataContext property for the window is set in code... After that, everything is data-bound.

                  Proud to have finally moved to the A-Ark. Which one are you in?
                  Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                  K 1 Reply Last reply
                  0
                  • I Ian Shlasko

                    DataContext is inherited, so when the window itself is created, set its DataContext to a root ViewModel class. Then when you use the code you just posted, it would bind to the "MainContent" property of that ViewModel, which would be your MainContentViewModel (Or whatever you decide to call it). The initial DataContext property for the window is set in code... After that, everything is data-bound.

                    Proud to have finally moved to the A-Ark. Which one are you in?
                    Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                    K Offline
                    K Offline
                    Kevin Marois
                    wrote on last edited by
                    #17

                    Got it! Thanks

                    If it's not broken, fix it until it is

                    I L 2 Replies Last reply
                    0
                    • K Kevin Marois

                      Got it! Thanks

                      If it's not broken, fix it until it is

                      I Offline
                      I Offline
                      Ian Shlasko
                      wrote on last edited by
                      #18

                      No problem, man. Glad we could help

                      Proud to have finally moved to the A-Ark. Which one are you in?
                      Author of the Guardians Saga (Sci-Fi/Fantasy novels)

                      1 Reply Last reply
                      0
                      • K Kevin Marois

                        Got it! Thanks

                        If it's not broken, fix it until it is

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

                        I insist you to look on my article, Building High Performance WPF/E Enterprise Class Application in C# 4.5[^] This will have greater help in understand what are all different layers, what need to considered for better performance, low memory oriented applications

                        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