简体   繁体   中英

Filters aren't updating Itemsource queries

It's a fairly basic question But I'm wonder why it's not updating or being dynamic. Basically the query should change when a different date is picked.

private DateTime StartDateTo;
public DateTime _StartDateTo { get { return _StartDateTo; } set { _StartDateTo = value;     Filter(); } }
private DateTime EndDateTo;
public DateTime _EndDateTo { get { return _EndDateTo; } set { _EndDateTo = value; Filter(); } }
private ObservableCollection<Quarterly> _QuarterlyInfo;
public ObservableCollection<Quarterly> QuarterlyInfo { get { return _QuarterlyInfo; } set{_QuarterlyInfo = value; Filter();} }


public ReportGridViewModel(IEventAggregator events)
{            
    EndDateTo = new DateTime(2013, 4, 1);
    StartDateTo = new DateTime(2010, 6, 30);
    QuarterlyInfo = new ObservableCollection<Quarterly>();
    Generalinfo = new Quarterly();          
    Filter();
}

public new void Filter()
{
    using (FBContext ctx = DB.Get())
    {
        QuarterlyInfo.Clear();
        //*************************** General Inquiry ******************************//
        Generalinfo = new Quarterly();
        var general = from z in ctx.Interactions
                      where z.ActivityDate >= StartDateTo && z.ActivityDate <= EndDateTo && z.Indepth == false
                      select new { Indepth = z.Indepth };
        Generalinfo.SectionInfo = "# of General Inquiries";
        Generalinfo.Result = general.Count();
        QuarterlyInfo.Add(Generalinfo);
    }
}

The information pulls, but won't update when parameters are changed.

xaml side:

<DatePicker x:Name="StartDateTo" SelectedDate="{Binding StartDateTo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<DatePicker x:Name="EndDateTo" SelectedDate="{Binding EndDateTo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<telerik:RadGridView ItemsSource="{Binding QuarterlyInfo, IsAsync=True}" AutoGenerateColumns="True">

Something like this should work:

    private DateTime _StartDateTo;
    public DateTime StartDateTo 
    { 
        get { return _StartDateTo; } 
        set 
        { 
            _StartDateTo = value;
            Filter();
            NotifyOfPropertyChange(() => StartDateTo);
        } 
    }
    private DateTime _EndDateTo;
    public DateTime EndDateTo
    { 
        get { return _EndDateTo; }
        set
        {
            _EndDateTo = value;
            Filter();
            NotifyOfPropertyChange(() => EndDateTo);
        }
    }
    private ObservableCollection<Quarterly> _QuarterlyInfo;
    public ObservableCollection<Quarterly> QuarterlyInfo
    {
        get { return _QuarterlyInfo; } 
        set 
        {
            _QuarterlyInfo = value;
            Filter();
            NotifyOfPropertyChange(() => QuarterlyInfo);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM