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

The Archive Base Latest Questions

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

I would like to use a datatemplate for my datagrid columns and have a

  • 0

I would like to use a datatemplate for my datagrid columns and have a button for each item. I would like the item to be removed if the user clicks the button. I am using the MVVM pattern. How would I accomplish this?

<DataGridTemplateColumn>
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <Button Width="50" Content="Remove" Command="{Binding RemoveItemCommand}"/>
    </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
  • 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:15:14+00:00Added an answer on May 23, 2026 at 3:15 pm
    public class ItemViewModel
    {
      public ItemViewModel()
      {
        RemoveCommand = new MyCommand(Remove);
      }
    
      public event EventHandler ItemRemoved;
      public ICommand RemoveCommand { get; private set; }
    
      private void Remove()
      {
        // Whatever it takes to remove item from your data store
        service.Remove(this.Data);
    
        var removeItem = ItemRemoved;
        if (removeItem != null)
          removeItem(this, EventArgs.Empty);
      }
    }
    
    public class ListViewModel
    {
      public ListViewModel(IEnumerable<ItemViewModel> items)
      {
        ItemVMs=new ObservableCollection<ItemViewModel>(items);
        foreach (var item in ItemVMs)
          item.ItemRemoved += RemoveSelectedItem;
      }
    
      public ObservableCollection<ItemViewModel> ItemVMs { get; private set; }
    
      private void RemoveSelectedItem(object sender, EventArgs e)
      {
        var item = sender as ItemViewModel;
        item.ItemRemoved -= RemoveSelectedItem;
        ItemVMs.Remove(item);
      }
    }
    

    Each item’s RemoveCommand would be bound to its button in your DataGrid. It sounds like you already have that part done. Make the ListViewModel’s ItemVMs property the data source for your DataGrid.

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

Sidebar

Related Questions

I would like to use the group_by method, but instead of using a column
I have a WPF DataGrid bound to ObservableCollection . Each item in my collection
I would like to show my user control inside row details. I have a
I'm adding TreeViewItems manually in code behind and would like to use a DataTemplate
I would like to set up a datagrid so that whenever an item is
I would like to use complex numbers as defined in C99, but I need
I would like to use HTML 4.01 Strict, and used a DOCTYPE of it
I would like to use KVO in the following context: 1) In touchesBegan:withEvent: I
I would like to use python to make system calls to programs and time
I would like to use a COM object in my application. How can I

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.