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

The Archive Base Latest Questions

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

I have the following XAML in a WPF application. I would like to bind

  • 0

I have the following XAML in a WPF application. I would like to bind the button to an ICommand in a view model. For some reason, I am not able to see the command from my view.
this is in a user control.

<Grid>
<Grid.DataContext>
        <Binding 
            x:Name="SettingsData"
            Path="Data" />
    </Grid.DataContext>
.
.
.
<DockPanel Grid.Column="1">
            <Button x:Name="SaveButton" 
                    DockPanel.Dock="Top"  
                    Height="25"  
                    HorizontalAlignment="Left" 
                    Margin="70 0 0 0"
                    Command="{Binding Path=SaveData}"

                    >Save Changes</Button>
        </DockPanel>
</Grid>

Here is my ICommand object –

public ICommand SaveData
{
    get
    {
        if (_saveData == null)
        {
            _saveData = new RelayCommand(
                param => this.saveData(),
                param => true
                );
        }
        return _saveData ;
    }
}

Does anyone have any idea why I cannot bind to this command?

Thanks for any thoughts….

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

    Looks like you are setting the DataContext of the Grid to the Data property of your ViewModel (or object). If the object that the Data property exposes doesn’t provide the SaveData command, you’ll have the problem you’re describing. Remember the DataContext is inherited from the parent.

    If you require that the DataContext is set in that manner, and still require the button to reference the parent DataContext, one option would be to use a RelativeSource to point to an element that has the ViewModel as the DataContext.

    In WPF you also have the option of making those commands static and using the {x:Static} markup extension to reach it.

    Hope that helps.

    EDIT: Here’s an example if your <Grid> is contained in a <UserControl>.

    <Button Command="{Binding Path=DataContext.SaveData, 
                              RelativeSource={RelativeSource Mode=FindAncestor, 
                                              AncestorType={x:Type UserControl}}}" ... />
    

    Also, I don’t know what your full XAML looks like, but I suspect that this can be simplified greatly by removing the DataContext on the Grid and Binding Data on the ItemsControl (or whatever you’re using to show the list of objects).

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

Sidebar

Related Questions

Good day all I have the following question: I would like to use Chart
I have a WPF control that I would like to overlay onto a WinForms
I have the following XAML: <TextBlock Text={Binding ElementName=EditListBox, Path=SelectedItems.Count} Margin=0,0,5,0/> <TextBlock Text=items selected> <TextBlock.Style>
I have the following XAML code, which displays a picture (image inside borders) and
Let's pretend I have the following xaml... <UserControl.Resources> <local:ViewModel x:Name=viewModel /> <local:LoadChildrenValueConverter x:Name=valueConverter />
I have following string String str = replace :) :) with some other string;
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I read about WPF and I have following concerns: Normally when we develop applications
I've decoupled events in this WPF application in the following way. What is the
I have following WPF ListView: <ListView Grid.Column=2 Grid.Row=1 Margin=0,53,12,6 Name=lvwProperties ItemsSource={Binding Path=SelectedPropertyItems, Mode=TwoWay} Grid.ColumnSpan=2>

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.