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

  • Home
  • SEARCH
  • 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 8238317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:46:20+00:00 2026-06-07T19:46:20+00:00

I want to create a new User Control which displays my own combobox. (The

  • 0

I want to create a new User Control which displays my own combobox. (The Combobox has a own style and other things…. (that comes later))

usercontrol xaml file:

<UserControl x:Class="WpfApplication1.MyCombobox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d" d:DesignWidth="500"
             Height="50">

    <ComboBox Height="42" ItemsSource="{Binding Path=MyItems}"></ComboBox>

</UserControl>

usercontrol code behind file:

namespace WpfApplication1
{
    public partial class MyCombobox
    {
        public MyCombobox()
        {
            InitializeComponent();

            MyItems = new List<ComboBoxItem>();
        }

        public List<ComboBoxItem> MyItems { get; set; }
    }
}

mainwindow xaml file:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WpfApplication1="clr-namespace:WpfApplication1" WindowStartupLocation="CenterScreen"
        Height="350"
        Width="500"
        >
    <Grid>
        <WpfApplication1:MyCombobox>
            <WpfApplication1:MyCombobox.MyItems>
                <ComboBoxItem Height="36">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="16" />
                                <RowDefinition Height="16" />
                            </Grid.RowDefinitions>
                            <TextBlock Text="Item Title 1" Grid.Row="0" FontWeight="Bold" />
                            <TextBlock Text="Item Description 1" Grid.Row="1" FontStyle="Italic" />
                        </Grid>
                    </Grid>
                </ComboBoxItem>
                <ComboBoxItem Height="36">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="1">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="16" />
                                <RowDefinition Height="16" />
                            </Grid.RowDefinitions>
                            <TextBlock Text="Item Title 2" Grid.Row="0" FontWeight="Bold" />
                            <TextBlock Text="Item Description 2" Grid.Row="1" FontStyle="Italic" />
                        </Grid>
                    </Grid>
                </ComboBoxItem>
            </WpfApplication1:MyCombobox.MyItems>
        </WpfApplication1:MyCombobox>
    </Grid>
</Window>

I wish that I can add, in the main window, the comboboxitems to my usercontrol. Like that:

<WpfApplication1:MyCombobox.MyItems>
    <ComboBoxItem Height="36">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="16" />
                    <RowDefinition Height="16" />
                </Grid.RowDefinitions>
                <TextBlock Text="Item Title 2" Grid.Row="0" FontWeight="Bold" />
                <TextBlock Text="Item Description 2" Grid.Row="1" FontStyle="Italic" />
            </Grid>
        </Grid>
    </ComboBoxItem>
    <!-- more items... -->
</WpfApplication1:MyCombobox.MyItems>

The UserControl combobox used the Items which are passed in the mainwindow.

When I run the code, it only displays an empty combobox

What’s wrong?

  • 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-07T19:46:23+00:00Added an answer on June 7, 2026 at 7:46 pm

    This has to do with the way you’re creating the binding to MyItems in the Combobox.

    To make it properly target the MyItems property in the code-behind, you can do the following:

    public MyCombobox() 
    { 
        InitializeComponent(); 
    
        MyItems = new List<ComboBoxItem>(); 
        this.DataContext = this;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a user control which would work the same way as
I create my own user control which only contains a panel : When I
I have a simple user control which I want to create dynamically every time
I want to create a new Rally user with the following C# code DynamicJsonObject
I am new to oracle , i want to create a user named as
I want to create a new field (or two) in my table that is
I want to create a new custom control derived from ContentControl (it will be
I have a user control which has a Canvas of height 100 and width
I have a user control which I want to define as a template in
We're trying to create a ListBox which has a few items inside that the

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.