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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:29:46+00:00 2026-06-06T12:29:46+00:00

Sorry, I’m thrashing around a bit learning MVVM, WPF, and XAML simultaneously. I have

  • 0

Sorry, I’m thrashing around a bit learning MVVM, WPF, and XAML simultaneously.

I have a problem that I created and I am completely confused with how this should be handled in MVVM.

What I have is a parent window that contains a user control that draws graphs. The graph drawing XAML used to be part of the parent window, but I moved it to a user control for organization as the parent window was very big.

In the parent windows XAML I have …..

<Window ....>
     <Window.Resources>
         <ViewModel:DropGraphViewModel x:Key="myViewModel"/>
     </Window.Resources>

     <!-- Set the data context to the view model. -->
     <Window.DataContext>
         <Binding Source="{StaticResource myViewModel}"/>
     </Window.DataContext>
     .....
</Window>

And then in the new user control XAML class I have a resource that is created that is a ‘generator’ class that serves up things that will be used by parts of the graph. It looks like this…

<UserControl ......
    <!-- Graph resources -->
        <Grid.Resources>
            <!-- The binding here for ItemsSource represents the collection the graph will be bound to -->

            <!-- THIS LINE DOESN'T WORK ANYMORE  -->
            <Graphs:LineChartGenerator x:Key="generator" ItemsSource="{Binding Source={StaticResource myViewModel}, Path=SampleData}" Width="500"  Height="200"> -->
        </Grid.Resources>

And then later on when I want to do some things like draw graph lines I used to reference the generator through binding.

    <!-- Connect the points -->
    <Polyline Points="{Binding Source={StaticResource generator}, Path=Points}" Stroke="Blue" />

What is now broken now that I am in am using a nested user control is that when I create the instance of the ‘generator’ class in the resources, I can’t pass in the binding that was ItemsSource=”{Binding Source={StaticResource myViewModel}, Path=SampleData}” because I no longer have access to the view model (myViewModel) that is in the static resource of the parent window! So I can’t set the binding during the creation time of the resource like I used to do.

What is the proper MVVM way to handle this type of pattern?

How do I inject the ItemsSource into my new user control so that it can pass it in when it creates the LineChartGenerator class instance?

  • 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-06T12:29:48+00:00Added an answer on June 6, 2026 at 12:29 pm
    1. DataContext is an inheritable DependencyProperty which means it trickles down the visual hierarchy.
    2. Resources are not part of visual tree until they are hosted.

    So in your case, your Graphs:LineChartGenerator has to be hosted in your UserControl and not delcared in the Resource section. Once you do that it acquires its own DataContext from the parent Window, this way as @GazTheDestroyer, pointed out you only need a implicit binding ItemsSource="{Binding SampleData}"

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

Sidebar

Related Questions

Sorry I have a problem with with the fancy left apostrophe showing up in
Sorry to ask something that others have already asked. But when I use the
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry for repost but I have a better working example of data that reflects
Sorry guys, didn't know how to word this one. Still learning jquery and have
Sorry for a long question and not a very descriptive title, but my problem
Sorry if this is a dup; I haven't found any questions that pose quite
Sorry for a pretty specific question. I have a table (see bottom), and when
Sorry. I'm just bitten (or bit. Go figure with this left-to-right language :-) I've
Sorry if this is a stupid question... I've developed an application that creates absolute

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.