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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:36:45+00:00 2026-05-27T10:36:45+00:00

My Custom UserControl’s dependency property will bind correctly if the value is statically defined

  • 0

My Custom UserControl’s dependency property will bind correctly if the value is statically defined in the XAML calling it, like this:

TextBoxText="myName"

but not if the value is bound dynamically itself:

TextBoxText="{Binding ItemTypeIdCode}"

There is my full Code.

Custom UserControl XAML:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="TestUserControl.UserControl1"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
x:Name="UserControl" Height="22" Width="282">

<Grid x:Name="LayoutRoot">
    <TextBlock TextWrapping="Wrap" Text="{Binding MyName, ElementName=LayoutRoot}"/>
</Grid>

Custom UserControl Code:

 public static readonly DependencyProperty TextBoxTextProperty =DependencyProperty.Register("TextBoxText", typeof(string), typeof(UserControl1));

    public string TextBoxText
    {
        get { return (string)GetValue(TextBoxTextProperty); }
        set { SetValue(TextBoxTextProperty, value); }
    }

In my Main Window XAML :

    <Grid x:Name="LayoutRoot">
    <Button Content="Button" Height="78" Margin="0,0,93,112" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="94" Click="MyButtonClick"/>
    <ListBox x:Name="MyListBox" HorizontalAlignment="Left" Margin="8,8,0,112" Width="192">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <local:UserControl1 HorizontalAlignment="Stretch" Margin="286,37,56,0" VerticalAlignment="Top" d:LayoutOverrides="Height" TextBoxText="{Binding MyName}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

In my Main Window Code :

    private void MyButtonClick(object sender, System.Windows.RoutedEventArgs e)
    {
        List<string> MyName = new List<string>();
        MyName.Add("Name 1");
        MyName.Add("Name 2");
        MyName.Add("Name 3");
        MyListBox.ItemsSource = MyName;
    }

This Code Successfully add my Custom UserControl as ListBoxItem in ListBox But Problem it is not display any text which i Binding.

I don`t understand where i am doing 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-05-27T10:36:45+00:00Added an answer on May 27, 2026 at 10:36 am

    You set the DataContext of the UserControl to itself, all bindings will then try to find the path on the UserControl, that is why you should not set the DataContext on UserControls.

    You should see a binding error in the Output window of Visual Studio saying something like:

    System.Windows.Data Error: 40 : BindingExpression path error: ‘ItemTypeIdCode’ property not found on ‘object’ ”UserControl1′ (Name=’UserControl’)’. …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm already familiar with property bindings in XAML. Now I've created a custom UserControl
I'm creating a Custom Usercontrol. It has two DependencyProperties I'd like to bind to
I have a Custom usercontrol that I want to enlarge. I tested this whit
Before I start, I have this code inside of a Custom Usercontrol: private DependencyProperty
I have an custom UserControl that displays an image, i'm trying to use this
When I right-click on my custom UserControl's BackColor property in the property-grid, then click
I'm trying to create a custom UserControl that will mimic auto-complete as it works
Ive created a custom UserControl that contains a single combobox. The currently selected value
I'd like to have a custom usercontrol based on textbox where I could type
I have a custom UserControl that have a StatusStrip. So, I resize this control

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.