I'm learning C# using visual studio express 2012, and I cannot find a source online that explains window content convention. What I mean by this is, what's the appropriate way to change the context / pass variables from the main window to different contexts?

I've been able to change the content of my window by creating and editing new UserControl classes. As for parameter passing, I've experimented with having a static mainwindow with public fields and passing mainwindow field values through action functions (with little success).

Is the appropriate way to handle changing the main window's context creating multiple usercontrol classes? If this is the case, should I be creating a tree with the main window as the root and the usercontrol classes as child elements?

Most of the questions I find when searching for an answer revolve around forms or new windows, which lead me to question whether usercontrol is the correct item for changing context. If I'm missing a tutorial or simple explanation I apologize in advance :D


What you want to look at is using the MVVM architectural pattern which strongly leverages the data binding feature of the .net framework (which is particularly good if you use WPF).

In this pattern, view models are represented by classes which are passed to the user control using the DataContext property. You can then use DataTemplate to fashion the UI as you wish at runtime according to the different types you use for your view models.

  • I'm going over a sample program using MVVM, and I have a question about performance. Is the MVVM mainly for simplifying large, commercial applications? I intend to program a game as my first project, and I'm wondering if this model will have performance issues if I have to execute an update loop 30 times per second. – user103049 Sep 24 '13 at 8:07
  • If you're willing to implement a game, don't use forms or WPF, just go for XNA which is Microsoft's game development framework. That wasn't clear in your question at all though. – SRKX Sep 24 '13 at 8:09
  • I didn't know that existed. Thank you :) – user103049 Sep 24 '13 at 8:10
  • @user103049: I am sure MVC-related patterns like MVVM or MVP can add some value to an XNA application, too. Decoupling your UI from your game logic will bring similar benefits like decoupling an UI from business logic. And when you use this to decouple your game logic's "clock rate" from your UIs clock rate, you can sometimes deal better with performance problems. – Doc Brown Sep 24 '13 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.