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. Load Usercontrols in MVVM

Load Usercontrols in MVVM

Scheduled Pinned Locked Moved WPF
wpfcsharpwcfarchitecturehelp
2 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.
  • J Offline
    J Offline
    jogisarge
    wrote on last edited by
    #1

    Hi @all, i know that there a many articles about my problem but i cant find a solution. I am new in WPF - MVVM and i try to understand the MVVM-Logic. So i made a little project to understand that. For my later apps i want to load UserControls dynamicly to my Window. In my StartView i have a Binding to the StartViewModel. (The Binding is in the APP.xaml)

    StartView app = new StartView();
    StartViewModel context = new StartViewModel();

    the StartView

    the StartViewModel

    namespace test.ViewModel
    {
    public class StartViewModel : ViewModelBase
    {
    #region Fields
    private UCStastistikViewModel _loadedControl;
    #endregion

        public StartViewModel()
        {
            LoadedControl = new UCStastistikViewModel();
        }
    
        #region Properties / Commands
        public UCStastistikViewModel LoadedControl
        {
            get { return \_loadedControl; }
            set
            {
                if (value == \_loadedControl)
                    return;
    
                \_loadedControl = value;
                OnPropertyChanged("LoadedControl");
            }
        }
        #endregion
    
        #region Methods
       
        #endregion
    }
    

    }

    UCStatistikView

    P 1 Reply Last reply
    0
    • J jogisarge

      Hi @all, i know that there a many articles about my problem but i cant find a solution. I am new in WPF - MVVM and i try to understand the MVVM-Logic. So i made a little project to understand that. For my later apps i want to load UserControls dynamicly to my Window. In my StartView i have a Binding to the StartViewModel. (The Binding is in the APP.xaml)

      StartView app = new StartView();
      StartViewModel context = new StartViewModel();

      the StartView

      the StartViewModel

      namespace test.ViewModel
      {
      public class StartViewModel : ViewModelBase
      {
      #region Fields
      private UCStastistikViewModel _loadedControl;
      #endregion

          public StartViewModel()
          {
              LoadedControl = new UCStastistikViewModel();
          }
      
          #region Properties / Commands
          public UCStastistikViewModel LoadedControl
          {
              get { return \_loadedControl; }
              set
              {
                  if (value == \_loadedControl)
                      return;
      
                  \_loadedControl = value;
                  OnPropertyChanged("LoadedControl");
              }
          }
          #endregion
      
          #region Methods
         
          #endregion
      }
      

      }

      UCStatistikView

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

      The standard way to display a usercontrol like this is to use a DataTemplate. Here's a simple data template that you could take and adapt as you need:

      <DataTemplate DataType="{vm:UCStastistikViewModel}">
      <view:UCStatistikView />
      </DataTemplate>

      Forgive your enemies - it messes with their heads

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

      My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

      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