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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:22:00+00:00 2026-06-10T17:22:00+00:00

I have a WPF datagrid that has two associated buttons for editing and deleting

  • 0

I have a WPF datagrid that has two associated buttons for editing and deleting data. Ideally, I’d like to disable or make these buttons invisible when an item is not selected in the grid. How do I approach this?

If it matters my datagrid XAML is:

<DataGrid AutoGenerateColumns="True" Margin="10,174,12,35" Name="dataGridArchiveQueue" Visibility="Visible" AlternatingRowBackground="#01000000" BorderBrush="#FF688CAF" 
                              HorizontalGridLinesBrush="#37000000" VerticalGridLinesBrush="#37000000" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" 
                              SelectedItem="{Binding SelectedItemArchiveGrid}" Grid.ColumnSpan="2">
                              <DataGrid.Resources>
                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                                                         Color="LightBlue" />
                        </DataGrid.Resources>

                    </DataGrid>
  • 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-10T17:22:01+00:00Added an answer on June 10, 2026 at 5:22 pm

    You can use DataTrigger on button to handle the disable/visible of buttons OR you can write the logic on CanExecuteChange event of command which gets binded to button

    Data Trigger

            <Button.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{SelectedItemArchiveGrid}" Value="{x:Null}">
                            <Setter Property="IsEnabled"Value="False"></Setter>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
    

    Command

    > public RelayCommand<object> DeletCommand { get; set; }
    > 
    > DeletCommand = new RelayCommand<object>(OnDelete, OnDeletCanExecute);
    > 
    > private void OnDelete(object obj) { }
    > 
    > private bool OnDeletCanExecute(object obj)  {
         return SelectedItemArchiveGrid != null;  }
    

    XAML

    <Button Content="Delete" Command="{Delete Command}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF DataGrid that increases in height when I add data to
In my application i have a WPF Window that has a DataGrid in it.
I have a WPF DataGrid that has another datagrid declared within the RowDetailsTemplate; <DataGrid
I have a wpf datagrid that has it's columns generated dynamically in code and
I have a WPF DataGrid templatecolumn that has a DataTemplate for an AutoCompleteBox from
I've got a WPF DataGrid that I have been using for some time, and
I have a WPF DataGrid who's data source is an ObservableCollection. It is set
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.
I have a user control that contains a WPF toolkit DataGrid . This control
I have a WPF DataGrid which has a DataTable as its ItemsSource . The

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.