Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6048735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:29:48+00:00 2026-05-23T07:29:48+00:00

I want to know how to add a user control into a window from

  • 0

I want to know how to add a user control into a window from a collection. Currently I am adding my control from my Views folder to a grid cell like so.

<views:MyControl Grid.Column="0" Grid.Row="0" Margin="10"/>

I have an ObservableCollection in my view model and it stores a collection of user controls. In my view I want to take one control from that collection and place it into the cell of my grid. How can I add a control to the grid like I have done above, but from my collection?

e.g something along the lines of {Binding Path controls.[1]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:29:49+00:00Added an answer on May 23, 2026 at 7:29 am

    If something contains a collection of user controls, it’s not a view model.

    A view model that backs a view which displays other controls should contain a collection of the view models for those controls. You should be bind the ItemsSource of an ItemsControl to the collection property, and then use template matching and data templates to create the controls.

    So, let’s suppose that you want to display a collection of FooView and BarView user controls in your window. You will create a FooViewModel class and a BarViewModel class, and then create a data template for each in the resource dictionary, e.g.:

    <Window.Resources>
       <DataTemplate x:Key="{Type local:FooViewModel}">
          <local:FooView />
       </DataTemplate>
       <DataTemplate x:Key="{Type local:BarViewModel}">
          <local:BarView />
       </DataTemplate>
    </WindowResources>
    

    Once this is done, any ItemsControl whose ItemsSource is bound to a collection of these view models will find the templates, create the controls, and bind them to the view models.

    If the ItemsControl you’re using is a Grid, you probably have an additional step. Any ItemsControl generates an item container (in the case of Grid, it’s a ContentPresenter) to hold the views it’s displaying; in a Grid, you probably need to assign the Grid.Row and Grid.Column to that container. Assuming that your view models have Row and Column properties, the way to do this is:

    <Grid.ItemContainerStyle>
       <Style TargetType="ContentPresenter">
          <Setter Property="Grid.Row" Value="{Binding Row}" />
          <Setter Property="Grid.Column" Value="{Binding Column}" />
       </Style>
    </Grid.ItemContainerStyle>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know how to add images while exporting the image from highcharts.
I want to add dll file into my project. But i don't know where
I've a user control UCConveyorBelt . My main window simply has a grid. I
I know how to add a control to the canvas/grid/layout- simply by calling canvas.Childern.Add()
I want to know how to add some sort of emblem or badge to
Also I want to know how to add meta data while indexing so that
I want to know that how can I add help support to my winform
i want to know that why do we add an app.config file in c#
All I want to know is if there's an easy way to add lines
I need to reinvent/recreate the Label Control from scratch to add my own mojoness

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.