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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:08:28+00:00 2026-05-23T10:08:28+00:00

I have an error when binding my command to a button in an ItemsControl.

  • 0

I have an error when binding my command to a button in an ItemsControl.

This is my code :

<phone:PhoneApplicationPage.DataContext>
    <ViewModel:MyViewModel />
</phone:PhoneApplicationPage.DataContext>

with :

<ItemsControl ItemsSource="{Binding MyList}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button Content="Test" 
                cmd:ButtonBaseExtensions.Command="{Binding MyViewModel.TestCommand}" 
                cmd:ButtonBaseExtensions.CommandParameter="{Binding}"/>
    </ItemsControl.ItemTemplate>
</ItemsControl>

And I get :

System.Windows.Data Error: BindingExpression path error: 'MyViewModel' property not found on '...' '...' (HashCode=77119633). BindingExpression: Path='MyViewModel.ChooseCommand' DataItem='...' (HashCode=77119633); target element is 'System.Windows.Controls.Button' (Name=''); target property is 'Command' (type 'System.Windows.Input.ICommand')..

Of course, I should use an absolute binding or a relative one, but I don’t know how to do that.

Thanks in advance for any 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-23T10:08:28+00:00Added an answer on May 23, 2026 at 10:08 am

    Your Button is within an ItemsControl which is bound to youur MyList property, which I am guessing is a List or some IEnumerable type. The DataContext of each Button will be the item within the MyList that it represents.

    You are correct that to bind the buttons to your top-level view model you would need some sort of relative source binding, which Silverlight (3) does not support.

    I created a relative source binding replacement for Silverlight here:

    http://www.scottlogic.co.uk/blog/colin/2009/02/relativesource-binding-in-silverlight/

    However, for WP7, where performance really matters, I would not use it!

    Why not simply create the relationship you need in your view model? i.e. for each item in MyList (let’s call them MyListItem), expose a property which points back to the parent view Model. In other Words, have a MyListItem.Parent property which points to MyViewModel.

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

Sidebar

Related Questions

I have this error message: Msg 8134, Level 16, State 1, Line 1 Divide
I have this error that is keeping me from moving forward. I basically have
This time I have an error which I have been trying again to figure
I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM
I have the following keybindings in my MainWindow: <KeyBinding Command={Binding OpenCommand} Gesture=Ctrl+O/> <KeyBinding Command={Binding
I have some Guice binding code using generics that compiles and functions fine from
Can anyone conjure from this code why the ItemsSource line would be getting a
I have some command binding defined in my XAML: <UserControl.CommandBindings> <CommandBinding Command=commands:Commands.GrantAccessCommand Executed=HelpExecuted />
So I have a check box that fires a command using WPF/MVVM this works
I have this problem with late binding: I am creating a grocery list application.

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.