views:

65

answers:

1

I'm working on a main window in my application and I would like to design parts of my window separately in Visual Studio designer.

Main window

  • Game desk (actually more of them and therefore it would be nice to design the game desk, mark it as a resource and then just via simple code (something like creating a new object and setting DataContext) create it.
  • Console
  • And so on

Is it possible in VS to do this thing?

I just need to know what to look for if it is possible. I don't need a whole solution.

Thank you for suggestions!

+1  A: 

ItemTemplates or UserControls are probably what you are looking for.

You can create ItemTemplates for things in a collection so they automatically get displayed one way or another and you can bind directly to the data in the class that is being represented by your ItemTemplate.

Often, I like to create a new UserControl instead. You basically create a new control with XAML. Then you can create instances and set the datacontext of each as you stated you'd like to do.

You can even use it in other XAML projects. Just be sure to add the namespace.Something like:

xmlns:lp="clr-namespace:LocalProject"

Then use it just like your other controls:

<StackPanel>
    <lp:YourUserControl DataContext="bind to an object of the correct type here" />
</StackPanel>

And in the code behind you'll be able to access the bound DataContext object:

YourCustomClass cc = this.DataContext as YourCustomClass;
Scott
Thank you, I'll have a look at it.
MartyIX