Open ice1e0 opened 4 years ago
I was going to open the same issue, glad it is already here.
Just to add, this has inspired MANY workarounds which should be a signal of how much of a problem it is. Examples:
https://tyrrrz.me/blog/wpf-listbox-selecteditems-twoway-binding
http://blog.functionalfun.net/2009/02/how-to-databind-to-selecteditems.html
https://stackoverflow.com/questions/40608981/how-to-get-selected-items-in-wpf-datagrid-using-mvvm
https://stackoverflow.com/questions/28429019/mvvm-datagrid-selecteditems-cant-bind
https://stackoverflow.com/questions/9218657/binding-selecteditems-to-a-observablecollection-property
https://stackoverflow.com/questions/8088595/synchronizing-multi-select-listbox-with-mvvm
Thanks
It would be realy great if you could implement the SelectedItems inside the DataGird/Listbox. Right now there is, as far as I know, just one solution, that works with virtualisation and a two way binding. See https://github.com/samueldjack/SelectedItemsBindingDemo This is the accepted solution from the https://stackoverflow.com/questions/9880589/bind-to-selecteditems-from-datagrid-or-listbox-in-mvvm , that already has been metioned by ice1e0
i have been following this issue for years and it is difficult for me to understand why something so obviously needed is not there. Please expand the functionality so that not everyone has to build something themselves - thanks!
@itsChris, could you contribute a PR that adds a DependencyProperty
for SelectedItems
to MultiSelector
?
How about https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagrid.selectedcellschanged ?
From: GFHuang @.> Sent: Saturday, August 20, 2022 3:53 PM To: dotnet/wpf @.> Cc: DGeiss2 @.>; Comment @.> Subject: Re: [dotnet/wpf] SelectedItems property on DataGrid (#3140)
I had try do define a attached property SelectedItemsCount for DataGrid, my idea is to subscribe DataGrid.SelectionChanged, then raise SelectedItemsCount changed event (maybe set the DataGrid.SelectedItems.Count to SelectedItemsCount for this purpose). But I can't find any entry point for subscribing DataGrid.SelectionChanged, does anyone have a good idea?
— Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fwpf%2Fissues%2F3140%23issuecomment-1221318933&data=05%7C01%7Cdgeiss%40kip.com%7Cbe08f292ac04418eade608da82b35764%7Cb965b6026aa642fe8b9936a0790307d1%7C0%7C0%7C637966004052259393%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=FiaQCdgvYGvrR9VxTMUxgW%2FzsfLxD0t3wPva96nFgws%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAOU5277AZWYDRBFMDHL47BTV2DPMVANCNFSM4N5N3BEQ&data=05%7C01%7Cdgeiss%40kip.com%7Cbe08f292ac04418eade608da82b35764%7Cb965b6026aa642fe8b9936a0790307d1%7C0%7C0%7C637966004052415623%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=m3MFgxZSTMBRX9l86Q4mTGVulf3TZ%2B3Fxwn7ux%2F%2FROI%3D&reserved=0. You are receiving this because you commented.Message ID: @.***>
@ice1e0 I suggest modifying the title of this issue to mention ListBox and/or ListView as well as DataGrid. Just because those others are also very common examples of this problem and that may make it easier for people to find this issue.
and
The actual problem may be in the Selector
or MultiSelector
base class but I doubt many people would actually search for that. (?)
The DataGrid has a property SelectedItems property which can not be used in WPF like 'SelectedItem' because it has no dependency property. I would love to see this be added to WPF.
See as well: https://stackoverflow.com/questions/9880589/bind-to-selecteditems-from-datagrid-or-listbox-in-mvvm Here the DataGrid is used with SelectionMode "Extended" and using SelectionUnit="FullRow" --> with this configuration I think there should be no issue adding this functionality.
Here a raw template for a simple extension (only supporting to read the 'SelectedItems' property):