MVVM Filtered + Filtering Event

2 posts, 0 answers
  1. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 25 Feb Link to this post

    Hi, when using the GridViewSelectColumn filters, it deselects the selecteditems. So I use this bit of code to fix it 

     

    private void LoanGrid_OnFiltered(object sender, GridViewFilteredEventArgs e)
    {
        LoanGrid.SelectedItems.AddRange(SelectedLoans);
    }
             
    public BindableCollection<LoanDTO> SelectedLoans { get; set; }
             
    private void LoanGrid_OnFiltering(object sender, GridViewFilteringEventArgs e)
    {
        SelectedLoans = new BindableCollection<LoanDTO>();
        foreach (var selectedItem in LoanGrid.SelectedItems)
        {
            SelectedLoans.Add((LoanDTO)selectedItem);
        }
    }

    That works perfectly fine, but I'm trying to have it be in MVVM format using caliburn.

    on xaml side,     cal:Message.Attach="[Filtered] = [Filtered];[Filtering] = [Filtering] "

    ViewModel

     

    private BindableCollection<LoanDTO> _oldLoans = new BindableCollection<LoanDTO>();
     
    public void Filtered()
    {
        SelectedLoans = new BindableCollection<LoanDTO>(Items.Where(x => _oldLoans.Any(y => y.Id == x.Id)));
    }
     
    public void Filtering()
    {
        _oldLoans = new BindableCollection<LoanDTO>();
        foreach (var selectedItem in SelectedLoans)
        {
            _oldLoans.Add(selectedItem);
        }
    }

     

    The selecteditems get cleared using the MVVM methods. Any thoughts?

  2. Stefan X1
    Admin
    Stefan X1 avatar
    521 posts

    Posted 01 Mar Link to this post

    Hi Minh,

    In order to handle a given event using the MVVM pattern, you can benefit from the EventToCommandBehavior mechanism. Can you please check it out and let me know how it goes?

    Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top