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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:29:07+00:00 2026-06-02T09:29:07+00:00

I have a WPF application where I need to do something like that :

  • 0

I have a WPF application where I need to do something like that :

<ItemsControl x:Name="lstProducts">
   <ItemsControl.ItemTemplate>
      <DataTemplate>
         <TextBlock Text="{Binding ProductName}" />
      </DataTemplate>
   </ItemsControl.ItemTemplate>
</ItemsControl>

I set the ItemsSource in code like this : lstProducts.ItemsSource = MyEFContext.Products;

Up to now everything is working fine. Now I want to use my own UserControl to display a product instead of the TextBlock like that.

<ItemsControl x:Name="lstProducts">
   <ItemsControl.ItemTemplate>
      <DataTemplate>
         <my:ProductItemCtl ProductName="{Binding ProductName}" />
      </DataTemplate>
   </ItemsControl.ItemTemplate>
</ItemsControl>

In my userControl, I created a DependencyProperty like that (see below) where I set the ProductName in the OnProductNameChanged callback.

The TextBlock in my usercontrol is not updated when binding the ItemsControl, and the callback is not launched.

#region ProductName

        /// <summary>
        /// ProductName Dependency Property
        /// </summary>
        public static readonly DependencyProperty ProductNameProperty =
            DependencyProperty.Register("ProductName", typeof(String), typeof(ProductItemCtl),
                new FrameworkPropertyMetadata("",
                    new PropertyChangedCallback(OnProductNameChanged)));

        /// <summary>
        /// Gets or sets the ProductName property. This dependency property 
        /// indicates ....
        /// </summary>
        public String ProductName
        {
            get { return (String)GetValue(ProductNameProperty); }
            set {  SetValue(ProductNameProperty, value); }
        }

        /// <summary>
        /// Handles changes to the ProductName property.
        /// </summary>
        private static void OnProductNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ProductItemCtl target = (ProductItemCtl)d;
            String oldProductName = (String)e.OldValue;
            String newProductName = target.ProductName;
            target.OnProductNameChanged(oldProductName, newProductName);
        }

        /// <summary>
        /// Provides derived classes an opportunity to handle changes to the ProductName property.
        /// </summary>
        protected virtual void OnProductNameChanged(String oldProductName, String newProductName)
        {
            // Set Product Name in the display Here!
            this.txtProductName.Text = newProductName;
        }

        #endregion
  • 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-02T09:29:10+00:00Added an answer on June 2, 2026 at 9:29 am

    Not an answer, but i can’t write this as comment. What happens if you simplify your code like this:

    public static readonly DependencyProperty ProductNameProperty = DependencyProperty.Register(
        "ProductName", typeof(string), typeof(ProductItemCtl), 
        new FrameworkPropertyMetadata(string.Empty,
            (o, e) => ((ProductItemCtl)o).txtProductName.Text = (string)e.NewValue)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple text box in a WPF application. I need to know
I have a WPF application from a client that I need to add a
I am developing a WPF application, and I need your advice. I have to
I have WPF C# application that communicate with a PLC (i.e. write/read Omron PLC's
I have a WPF application (.NET 3.0, VS2008) that displays data in a tab
I have a wpf application (C#) that needs to copy a file to a
We have a WPF Application that runs from both desktop and as a XBAP
I have a WPF application with several windows. I would like to define GLOBAL
I have wpf user control <StackPanel Orientation=Horizontal> <TextBox Name=txbInterval Text=5/> <Image Name=imgStart Source=Images/start.png/> <Image
I'm writing a WPF desktop application and have a view that needs to look

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.