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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:39:20+00:00 2026-06-01T23:39:20+00:00

I am using Silverlight 4 and the MVVM pattern. My view model has two

  • 0

I am using Silverlight 4 and the MVVM pattern.

My view model has two properties:

  • SomeProperty and
  • MyCommand

SomeProperty is a complex type and has a lot of subproperties. MyCommand is a property to handle commanding from a Button.

I have a child window (the view) with a Grid as the LayoutRoot which is bound to the SomeProperty property of the view model.

<Grid x:Name="LayoutRoot" DataContext="{Binding SomeProperty, Mode=TwoWay}">
    ...
</Grid>

However, inside the Grid I want to bind a Button’s Command property to the MyCommand property of the view model:

<Button Command={Binding MyCommand} />

But this is not working because MyCommand is a property of the view model, and not a property of the view model’s SomeProperty property. (When I click on the Button it does not execute the command.)

Anywho, is there a way using data binding in Silverlight 4 such that I can have a container UI element set its DataContext property explicitly, but then have a different control within the container reference a property that’s a sibling (or parent or whatever) of the DataContext of the containing control?

My current workaround is to define the binding in the view’s class, but I’d rather have it in the XAML.

Thanks

  • 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-01T23:39:21+00:00Added an answer on June 1, 2026 at 11:39 pm

    If you give your root element (ChildWindow, UserControl, whatever) a name, then you can use ElementName to get to the view model.

    <UserControl x:Name="MyUserControl">
        <Grid x:Name="LayoutRoot" DataContext="{Binding SomeProperty, Mode=TwoWay}">
            <Button Command="{Binding MyCommand}" DataContext="{Binding DataContext, ElementName=MyUserControl}" />
        </Grid>
    </UserControl>
    

    Or, here’s another way to do the same thing.

    <UserControl x:Name="MyUserControl">
        <Grid x:Name="LayoutRoot" DataContext="{Binding SomeProperty, Mode=TwoWay}">
            <Button Command="{Binding DataContext.MyCommand, ElementName=MyUserControl}" />
        </Grid>
    </UserControl>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the article Model View View-Model (MVVM) in Silverlight as a basis to
I am writing an app using the MVVM (Model-View-ViewModel) pattern and am leveraging the
I'm writing a Silverlight app using the MVVM pattern. I have a main view
My Scenario: I'm using a Silverlight MVVM pattern. All my view models inherit from
I'm creating a Silverlight 3.0 MVVM application using Silverlight.FX but my View is actually
I have a silverlight bing map application. I am using the MVVM pattern with
I have a Silverlight app that is using the MVVM pattern. I have a
I'm trying to create an silverlight application using the MVVM design pattern. It's a
I am using Silverlight 4 and MVVM pattern for my application. I have a
I am building a silverlight application using MVVM pattern but I don't understand what

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.