Cannot seem to fire DeleteCommand when button is an datagrid. Selected event always fires - wpf

I have a Wpf Form with a tabControl with 2 tabs "Customers" and CustomerDetail"
First Tab is a list of all Customers populated in a datagrid and delete Button as a dataTemplate on each line of the grid.
Selecting a customer it gets the customer details and moves to the second tab.
This all in MVVM and the delete button is mapped to a DeleteCommand .All good.
My Problem
It cannot seem to distinguish when clicking on the delete button it fires the selected event and goes to the other tab.I dont want it to go to the other tab when pressing delete.
How can I do it?
User selects row and should go to the other tab.
Row is selected and presses delete button just trigger the delete command.
Hope all clear
Any suggestions?

Try using DoubleClick event for showing CustomerDetails tab. so, when user click on delete button, they just fire click command of the datagrid and nothing happen...

Related

How to show a dialog on click of a combobox item using MVVM?

I am having a combo box control in which I had inserted three items(For instance X,Y,Z respectively). I want to show a dialog when "X" item in the combobox is clicked. In order show a dialog upon click on "X" item, I was able to handle it in "SelectionChanged" event. But the problem here is when I click on the same item no event is getting triggered and as a result I am not able to show a dialog on click on "X" item.
How can I accomplish this issue using MVVM pattern.
I am very new to WPF, please be kind with your answers.

WinForms: can a menu click handler determine which edit control on the form had focus immediately preceding the click?

WinForms.
Let's say we have a grid on the form with some cell editors (checkboxes, radio button groups). The form has a file menu. File -> Save. User visits a few cells in the grid, and clicks a checkbox in a cell, and, without touching anything else with the mouse and without touching the Tab key, clicks on the File menu and then clicks Save.
Inside the Save menuitem click handler, is it possible to determine which checkbox in the grid had focus immediately prior? That checkbox won't have lostfocus yet because a menu choice doesn't cause its lostfocus event to fire.

How to detect a click on the selected row of a RadGridView control

My WPF application uses the Telerik RadGridView control on a few of its screens. I have a requirement that says that whenever the user clicks on a row in the RadGridView, I'm supposed to switch to another screen and display detail information about that row. I hooked up a handler to the SelectionChanged event and this works, except that nothing happens if the user clicks on the selected row a second time. This makes sense, as the selected row isn't being changed.
How can I detect a second click on the same row and have the second screen displayed?
Tony
You could just attach a handler to the MouseUp event on the GridView. Check if there are any selected cells and respond from there. This will fire even if there is already a selection.
The MouseDown event will fire on the mouse click, but before the gridview updates the selction, mouse up should fire when the selection has already been adjusted
You can also attach a handler to each individual cell in code-behind as follows
(this.GridView as RadGridView).AddHandler(
GridViewCell.MouseUpEvent,
new EventHandler<Telerik.Windows.RadRoutedEventArgs>(this.OnMouseUp));
I think you may try to achieve this through the MouseLeftButtonDown event or PreviewMouseLeftButtonDown event.

Datagrid Command Binding to buttom, don't select row

I have a command bound to a button on my datagrid (e.g. button shows for everyrow).
Basically the command is wired to an object which shows children of that row in a pop up window.
Problem is the customers wants it to display the chid data but not actually select that row in the datagrid.
you have some options:
you can use a style
you can the UnSelectAll() method
and if you google you will find some more
EDIT:
did you try to handle the PrevievMouseDown Event? you can set e.Handled=true if the user click on the button.

Toggle Selected Row in WPF DataGrid

I want to be able to toggle selection when a row is clicked. So, first click should highlight it and second click (again on the row) should unhighlight it (and fire an event). Is it even possible? I'm using a OnSelectionChanged event but that gets fired only when I click on a different row than the selected one.
there a some useful answers here(searching the visual tree) or here(check in PreviewMouseLeftButtonDown).

Resources