Open hanyscz opened 3 weeks ago
Have the same question, somehow I would like to bind to the filtered collection in my viewmodel
Hi, You can see demo app
I see in the sample app you are binding the 'FilteredList', but the filteredlist is computed in the ViewModel.
I would like the user to use the filter menu's and iterate over what is left in the UI from a command.
Am I missing something?
be more explicit, I don't understand what you want to do, make pseudo code if necessary
Thanks for the reply. I see i wasn't very clear in my previous comment ;)
What I mean is, if I have 8 items in my ObservableCollection that is bound to the DataGrid, and I filter it down to 2 items by using the popup menu's, how do I access the filtered collection in my ViewModel.
Filtering the DataGrid does not change the source, and that's all I have in the ViewModel.
I saw you wrote the .Items property contains the filtered collection, but in that case I can't find a 'clean' way to get this collection into my VM.
EDIT: Only way I can do it now is by doing this in the code-behind:
public partial class PartsGridPage : Page
{
public PartsGridPage(PartsGridViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
PartsGrid.Items.CurrentChanged += Items_CurrentChanged;
}
private void Items_CurrentChanged(object? sender, EventArgs e)
{
((PartsGridViewModel)DataContext).FilteredSource = PartsGrid.Items.Cast<PartGridItemViewModel>().ToList();
}
}
Your solution seems correct to me. I agree with you that having to cast the Items collection to get the resulting collection from the filtering is not elegant at all, but I haven't found any other way to do it. If you look at the source code of FilterDataGrid, I call this method several times.
I worked for several days to find an alternative and finally I had to resign myself because the code I produced was not more efficient. if you find an alternative, let me know
Hi, how can I enable getting filtered data into another collection? Is there an output, or is it not possible? Maybe I’m looking at it incorrectly.