0

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!

2

1 Answer 1

1

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;
1
  • Thank you, I'll have a look at it.
    – MartyIX
    Apr 6, 2010 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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