SelectedDate is updated later after SelectionChanged event invoked

3 posts, 1 answers
  1. Hao
    Hao avatar
    4 posts
    Member since:
    Aug 2011

    Posted 19 Sep 2011 Link to this post

    Hi Telerik,

    I have a RadDatePicker and its SelectedDate value is binding with BeginDate property. What I want to do is to update other RadDatePicker when this RadDatePicker's value gets changed.

    However, after SelectionChanged event is invoked, I still get the old date value inside the Command. When the event get finished, the property is finally updated. So I am not able to update the other RadDatePicker after SelectionChanged is invoked.

    Could you please to help me with this? Thanks.

    Hao L


    Below is my codes:
    ----------------------------------------------------------------
    //View [xaml]:
    <telerik:RadDatePicker Name="BeginDatePicker" Width="100" telerik:StyleManager.Theme="Metro" SelectedDate="{Binding Source={StaticResource ClrStmtControlViewModel}, Path=BeginDate, Mode=TwoWay}" IsReadOnly="False">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction Command="{Binding Source={StaticResource ClrStmtControlViewModel}, Path=OnBeginDatePickerSelectionChangedCommand, Mode=OneWay}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </telerik:RadDatePicker>

    //View Model:

    //Property
            private DateTime _BeginDate;
            public DateTime BeginDate
            {
                get { return _BeginDate; }
                set
                {
                    _BeginDate = value;
                    RaisePropertyChanged("BeginDate");
                }
            }
     
    //Command
            private readonly ICommand _OnBeginDatePickerSelectionChangedCommand;
            public ICommand OnBeginDatePickerSelectionChangedCommand
            {
                get
                {
                    return _OnBeginDatePickerSelectionChangedCommand;
                }
            }
            private void BeginDatePicker_SelectionChanged()
            {
                AppMessaging.UpdateBeginDateMessage.Send(BeginDate); //BUT THE DATE IS NOT CHANGED HERE!!!
            }


  2. Answer
    Yana
    Admin
    Yana avatar
    4554 posts

    Posted 26 Sep 2011 Link to this post

    Hi Hao,

    Please try setting CommandParameter like this:

    <telerik:RadDatePicker Name="BeginDatePicker" Width="100" telerik:StyleManager.Theme="Metro"
                            SelectedDate="{Binding Source={StaticResource ClrStmtControlViewModel}, Path=BeginDate, Mode=TwoWay}" IsReadOnly="False">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="SelectionChanged">
                <i:InvokeCommandAction
                    Command="{Binding Source={StaticResource ClrStmtControlViewModel}, Path=OnBeginDatePickerSelectionChangedCommand, Mode=OneWay}"
                    CommandParameter="{Binding ElementName=BeginDatePicker}" />
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </telerik:RadDatePicker>

    and then find the date in the event handler like this:

    private void BeginDatePicker_SelectionChanged(object param)
    {
      var selectedValue = (param as RadDatePicker).SelectedValue;       
    }


    Best wishes,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Hao
    Hao avatar
    4 posts
    Member since:
    Aug 2011

    Posted 26 Sep 2011 Link to this post

    Thanks a lot. Problem solved!!
Back to Top