Reputation: 28666
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
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!
Upvotes: 0
Views: 1067
Reputation: 12050
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;
Upvotes: 1