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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:44:51+00:00 2026-06-04T15:44:51+00:00

I am developing a control in WPF, my control contains some other WPF controls

  • 0

I am developing a control in WPF, my control contains some other WPF controls such as labels, buttons and one DataGrid. So, what I have been trying to do is to create a dependency property that allows me to get the DataSource for my dataGrid from the outside of my container control.

So far I have this code:

public static readonly DependencyProperty dataSourceProperty = DependencyProperty.Register(
                                                                            "DataSource",
                                                                            typeof(object),
                                                                            typeof(MyCustomControl));
    public object DataSource
    {
        get
        {
            return (object)GetValue(dataSourceProperty);
        }
        set
        {
            SetValue(dataSourceProperty, value);
        }
    }

But what I cant figure out is where I have to write this code:

    myDataGrid.ItemsSource = DataSource;

I mean, what I need is, in my xaml file, be able to do this:

<MyCustomControl Name="MyControl" DataSource={Binding MyData}/>

I hope you can help me. Thank you in advance.

  • 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-04T15:44:52+00:00Added an answer on June 4, 2026 at 3:44 pm

    After some hours of research I’ve found the solution to my problem:

    Since I needed to have access to a nested control dependency property from the container control I did this:

    public static readonly DependencyProperty itemsSourceProperty = ItemsControl.ItemsSourceProperty.AddOwner(
                                                                            typeof(MyCustomControl), 
                                                                            new FrameworkPropertyMetadata(
                                                                                ItemsSourcePropertyChangedCallback));
    
        public System.Collections.IEnumerable ItemsSource
        {
            get
            { return (System.Collections.IEnumerable)GetValue(itemsSourceProperty); }
    
            set
            { SetValue(itemsSourceProperty, value); }
        }
    
        private static void ItemsSourcePropertyChangedCallback(DependencyObject controlInstance, DependencyPropertyChangedEventArgs args)
        {
            MyCustomControlraceUIGridControlInstance = (MyCustomControl)controlInstance;  
            raceUIGridControlInstance.extendedDataGrid.ItemsSource = (System.Collections.IEnumerable)args.NewValue;            
        }
    

    After doing that you can write in you XAML:

    <MyCustomControl Name=mycustomControl ItemsSource="{Binding YourData}" />
    

    You can do this with any nested control dependency property.

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

Sidebar

Related Questions

Suppose that you are developing a custom control in WPF that contains internally some
I'm developing a graph control in WPF. I have previously developed it using GDI
I'm developing an application in WPF and .Net 4 which contains animations. My controls
I am developing a WPF app that contains a webbrowser control that loads a
I am developing a WPF application, and I have created a user control called
Greetings I started developing with WPF yesterday and have ran into some issues. I
I'm developing a WPF user control that contains a ComboBox. The ComboBox choices are
I'm developing a WPF application using MVVM. Inside a Window, I have a control
I am developing a smart tag for one of my WPF controls. The smart
We have a system built using WPF and have (until recently) been developing using

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.