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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:12:24+00:00 2026-05-16T07:12:24+00:00

if the parent’s datasource has a child property that is a collection (let’s say

  • 0

if the parent’s datasource has a child property that is a collection (let’s say it is called ChildCollection) is there a trick to reference it?

So, this code sample is basically what I am attempting to do. But when I use this approach I do not get any data to my child controls.

<UserControl>
    <UserControl.Resources>
        <sample:Data x:Key="MyData" />
    </UserControl.Resources>
    <Canvas DataContext="{StaticResource MyData}">
        <TextBlock Text="{Binding Title}" />
        <My:UserControl DataContext="{Binding ChildCollection}" />
    </Canvas>
</UserControl>

My dependency property looks like this:

public static readonly DependencyProperty DataProperty =
    DependencyProperty.Register("Data", typeof(IEnumerable), typeof(ButtonList), 
    new UIPropertyMetadata(new PropertyChangedCallback(DataChanged)));
public DoubleCollection Data
{
    get { return (DoubleCollection)GetValue(DataProperty); }
    set { SetValue(DataProperty, value); }
}
static void DataChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
    (sender as FrameworkElement).DataContext = e.NewValue;
}
public void SetData(IEnumerable data)
{
    (View as CollectionViewSource).Source = data;
}

Thank you in advance for your help.

  • 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-16T07:12:25+00:00Added an answer on May 16, 2026 at 7:12 am

    If I understand your code right, you want the collection to be in the UserControl’s DataProperty.

    To achieve this, you have to do the Binding like this:

     <Canvas DataContext="{StaticResource MyData}">
        <TextBlock Text="{Binding Title}" />
        <My:UserControl Data="{Binding ChildCollection}" />
     </Canvas>
    

    Instead of:

    <Canvas DataContext="{StaticResource MyData}">
        <TextBlock Text="{Binding Title}" />
        <My:UserControl DataContext="{Binding ChildCollection}" />
     </Canvas>
    

    Hope this is helpful. Also: I dont know if a canvas inherits it’s DataContext to childs. Use a Panel instead (Grid/Stackpanel/WrapPanel).

    Jan

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

Sidebar

Related Questions

each parent has an Id each child object has a property ParentId that identifies
Using parent child relationship where a parent can have children while each child has
If you have Parent has_many :children Child Is there any reason a foreign key
I have a parent project that is branched to many dependent child projects. I
A parent has several child threads. If user click on stop button the parent
Parent Div Click Function gets called when Child Div Click is clicked. How to
If parent window A passes a reference to itself to child window B (via
Parent is a UIImageView, child is a UIImageView. Both have enable user interaction set
If Parent has_many :children , must Child :belongs_to :parent ?
So I have a parent that defines a onmouseup event that hide/display a table.

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.