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 8813143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:46:16+00:00 2026-06-14T03:46:16+00:00

I have a DataGrid bound to a collection view model. The element view model

  • 0

I have a DataGrid bound to a collection view model. The element view model has a property called UI of type UIElement. The scenario is that I want the generated UIElement to be bound.

So for example (imaginary toy example), say the UIElement is a TextBlock with a text Foo, then I want the DataGrid to have rows of TextBlock‘s with the text Foo.

The reason why I want this is not important here.

So how might one databind to a property of type UIElement where the UIElement is injected as the databound content?

  • 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-06-14T03:46:17+00:00Added an answer on June 14, 2026 at 3:46 am

    Well, you can just go ahead and do it I guess.

    This small piece of code pretty much does what you want i believe..

    XAML:

    <DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False">
        <DataGrid.Columns>
            <DataGridTemplateColumn>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <ContentControl Content="{Binding UI}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
    

    Code-behind:

    public partial class MainWindow : Window
    {
        public List<Model> Items { get; set; }
    
        public MainWindow()
        {
            InitializeComponent();
    
            var textblock = new TextBlock();
            textblock.Text = "I'm a textblock";
    
            var button = new Button();
            button.Content = "I'm a button";
    
            var combobox = new ComboBox();
            combobox.Items.Add("Item1");
            combobox.Items.Add("Item2");
    
            this.Items = new List<Model>(new[] { 
                new Model(textblock),
                new Model(button), 
                new Model(combobox)
            });
    
            this.DataContext = this;    
        }
    
        public class Model
        {
            public UIElement UI { get; set; }
    
            public Model(UIElement ui)
            {
                this.UI = ui;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a view model, I have a collection of items of type ClassA called
I have a DataGrid bound to a PagedCollectionview property of my View-Model. I've added
I have a View that displays a DataGrid which is bound to an ObservableCollection
I have a datagrid bound to a CollectionViewSource view in my view model. The
I have an ObservableCollection that is bound to a DataGrid where I want the
I have a DataGrid that has AutoGenerateColumns=True. I'm binding that DataGrid to a collection
Here's my problem: I have a datagrid that is bound to a collection of
I have a datagrid that's bound to an observablecollection object. The collection may be
I have a datagrid bound to an observable collection of objects. What I want
I have a DataGrid in WPF bound to an observable collection. In my UI

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.