DataGrid DataGridTemplateColumn Button SelectedItem null if row is not selected #17167
Replies: 6 comments 1 reply
-
Please try to make it a minimum sample to reproduce. If you need help for a complete App, please request paid support. Thanks for your understanding. |
Beta Was this translation helpful? Give feedback.
-
The problem also occurs with "public Country SelectedCountry" in https://github.com/evilbaschdi/EvilBaschdi.Core.Avalonia/blob/develop/src/EvilBaschdi.Core.Avalonia.DummyAppMvvm/ViewModels/ExtendedInformationViewModel.cs is that minimum enough? |
Beta Was this translation helpful? Give feedback.
-
From a first view it looks like you never raise PropertyChanged when you update SelectedContry. Thus the UI will not know about the new selection made. Tip Do you have a basic understanding about MVVM? If not I suggest you check out Avalonia.Samples about mvvm usage. |
Beta Was this translation helpful? Give feedback.
-
Even if I do raise RaisePropertyChanged inside the setter of the SelectedItem its not working because that setter never gets called. |
Beta Was this translation helpful? Give feedback.
-
it is depended on several other projects and even a feed that I don't know. I cannot check all of the code if it is save to run, which I have to do to debug it on my own. What I can think of is that Button will raise the command before DataGrid gets the possibility to select a row. I suggest to add a CommandParamter to your Command which you simply bind to the rows DataContext. Here is a working sample, maybe you can check out what I did and adopt it. |
Beta Was this translation helpful? Give feedback.
-
thx for your example but its implemented with that CommunityToolkit. But I (still?) Use ReactiveUI |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I'm not sure, if is really a bug in the code or if I do something wrong, but I need help here :-)
I've migrated some WPF Application to Avalonia some time ago. Both using MVVM
In both worlds I've hosted a Button inside a DataGrid Column to start an action here.
Now the issue is that the SelectedItem of the DataGrid is NULL if I just hit that Button in case I do not select the containing row before.
But! working with the NumericUpDown inside the same row makes not problem.
So maybe there's some problem while defining my Command
To Reproduce
Repository: https://github.com/evilbaschdi/VmMachineHwVersionUpdater (develop branch contains a debug zip file)
Project: VmMachineHwVersionUpdater.Avalonia
Extracting vmware.zip for Grid Data:
Application Functionality:
Using the DataGrid:
SelectedMachine and ICurrentItem:
They assign the current item to "ICurrentItem" without requiring explicit row selection.
Expected behavior
As already mentioned before; I'm not 100% sure if this an issue of Avalonia. Maybe it also could be that my Buttom.Command is defined wrong.
Avalonia version
11.1.1
OS
Windows
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions