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

I have the following xaml for changing the image for WPF button when mouse
I have the following XAML below for the main window in my WPF application,
I have an error with my Xaml files in a WPF application. I'm not
I have the following binding in my wpf application xaml: <TextBox Text={Binding Amount, StringFormat=c}
I have the following WPF application <Window x:Class=Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:WpfApplication1 Title=Window1 Height=300 Width=300>
I am developing wpf application. I have only one button in xaml page. On
I am NEW to WPF. I have the following XAML code: </Window> ... <Canvas>
Good day all I have the following question: I would like to use Chart
I have the following WPF window definition but the focus/lost focus events are not
I have following code in WPF XAML and want it to be converted to

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.