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. How to have duplicate model/view-model in TabControl

How to have duplicate model/view-model in TabControl

Scheduled Pinned Locked Moved WPF
tutorialquestion
4 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.
  • L Offline
    L Offline
    Leif Simon Goodwin
    wrote on last edited by
    #1

    I have a view which populates tab controls as follows:

    The above has been simplified for clarity. What I want is two instances of the LogFileViewModel and LogFileView pair in the tab, one for video files and one for RFID files. However, the above does not allow me to have the same model class twice, for reasons that are fairly obvious. I have got round this by deriving classes from LogFileViewModel, called VideoLogFileViewModel and RfidLogFileViewModel, which initialise the base class appropriately. The tab control obtains the view model instances from the ViewModels property of the main view model. Hence my workaround makes sure that there are no duplicate view model class instances. However, it is inelegant. Is there some more elegant way of doing this? I was wondering is there is some jiggery pokery I can add to the to allow it to identify a specific instance of LogFileViewModel i.e. to compare a string property with a fixed value.

    P 1 Reply Last reply
    0
    • L Leif Simon Goodwin

      I have a view which populates tab controls as follows:

      The above has been simplified for clarity. What I want is two instances of the LogFileViewModel and LogFileView pair in the tab, one for video files and one for RFID files. However, the above does not allow me to have the same model class twice, for reasons that are fairly obvious. I have got round this by deriving classes from LogFileViewModel, called VideoLogFileViewModel and RfidLogFileViewModel, which initialise the base class appropriately. The tab control obtains the view model instances from the ViewModels property of the main view model. Hence my workaround makes sure that there are no duplicate view model class instances. However, it is inelegant. Is there some more elegant way of doing this? I was wondering is there is some jiggery pokery I can add to the to allow it to identify a specific instance of LogFileViewModel i.e. to compare a string property with a fixed value.

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

      As long as you had something in there that identifies whether the template is for RFID or for video, you can use the technique I demonstrate here[^] to switch to the appropriate template. All you need is something to trigger on.

      This space for rent

      L 1 Reply Last reply
      0
      • P Pete OHanlon

        As long as you had something in there that identifies whether the template is for RFID or for video, you can use the technique I demonstrate here[^] to switch to the appropriate template. All you need is something to trigger on.

        This space for rent

        L Offline
        L Offline
        Leif Simon Goodwin
        wrote on last edited by
        #3

        Thanks Pete This is probably ignorance on my part but I'm not sure how that would work with my case, since I want two instances of the same template visible at the same time, or more precisely, present at the same time since you can only view one tab at any given time. I need to think about this more!

        P 1 Reply Last reply
        0
        • L Leif Simon Goodwin

          Thanks Pete This is probably ignorance on my part but I'm not sure how that would work with my case, since I want two instances of the same template visible at the same time, or more precisely, present at the same time since you can only view one tab at any given time. I need to think about this more!

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

          You're using two separate ViewModel instances - the appropriate template will be rendered in place based off the ControlTemplate.

          This space for rent

          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