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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:01:13+00:00 2026-05-23T15:01:13+00:00

I am at a loss over something that is probably incredibly simple. I did

  • 0

I am at a loss over something that is probably incredibly simple.
I did search but faield to find an exact answer that i needed.

The problem is as followed.

I am teaching myself silverlight MVVM.
Currently I’m writing an application that uses 1 mainpage and 2 usercontrolls.

As you can imagine, 3 viewmodels.

Currently in my XAML:

mainpage.xaml

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"
xmlns:vm="clr-namespace:newFileupload.ViewModel"
xmlns:vw="clr-namespace:newFileupload.View"

<UserControl.DataContext>
    <vm:MainPageViewModel />
</UserControl.DataContext>

<Grid x:Name="LayoutRoot" Background="White">
    <vw:PicturesOverviewView />
</Grid>

PicturesOverviewView.xaml

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"

<Grid x:Name="LayoutRoot" Background="White">

</Grid>

So in mainpage.xaml, I set the datacontext in xaml, i then call the usercontrol in the grid like so:

<vw:PicturesOverviewView />

This gives me the following error:

Error   1   Cannot create an instance of "PicturesOverviewView".    C:\Programming\C#\newFileUpload\newFileupload\MainPage.xaml 16  9   newFileupload

I have absolutely no clue what is causing this, and secondly..

How do I bind view models to the appropriate usercontrol?

Do I need to declare the view namespace for every usercontrol and then set its datacontext like the mainpage?

Thanks for taking the time to read and I hope to be able to continue soon 🙂

  • 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-23T15:01:14+00:00Added an answer on May 23, 2026 at 3:01 pm

    If the code shown is correct, you are attempting to create a PicturesOverviewView control inside a PicturesOverviewView control. That will account for the compile error. (I am guessing though that you have cut & Paste the same Xaml twice).

    Binding-wise:
    You want to bind the child controls to properties on the main view Model, that are themselves view models

    e.g.

    namespace newFileupload.ViewModel
    {
        public class MainPageViewModel
        {
            public ChildViewModel1 ChildViewModel1 { get; set; }
            public ChildViewModel2 ChildViewModel2 { get; set; }
    
            public MainPageViewModel()
            {
                this.ChildViewModel1 = new ChildViewModel1() { SomeProperty = "hello"};
                this.ChildViewModel2 = new ChildViewModel2() { SomeProperty = "there" };
            }
        }
    }
    

    Then the MainPage binds like this:

    <Grid x:Name="LayoutRoot" Background="White">
        <vw:PicturesOverviewView DataContext="{Binding Path=ChildViewModel1}" />
        <vw:PicturesOverviewView DataContext="{Binding Path=ChildViewModel2}" />
    </Grid>
    

    Something somewhere needs to create your view models with the right data. It makes sense to hangs the children off the parent viewmodel.

    I would suggest you look at using IOC injection (e.g. using Unity) as it sounds like you may simply wish to create singletons referenced at various levels. The issue is where do you want to provide re-use as if you hard-wire data contexts in the child views you cannot reuse them.

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

Sidebar

Related Questions

I'm at a loss, I can't see the reason something as simple as this
Every now and again I find myself doing something moderately dumb that results in
I have have searched all over for a tutorial or something that could show
I'm a bit at a loss as to how to find a clean algorithm
I'm looking for a Windows network emulator that can emulate the packet-loss & latency
I did some testing with floating point calculations to minimize the precision loss. I
I don't know too much about h.264, but the thing is that I've got
I've been searching here and Google, but I'm at a loss. I need to
I read all over the Amazon documentations, but I'm still confused or should I
The code is fairly simple --- the issue is that there is an invalid

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.