ScheduleView Appointment Binding Issues

19 posts, 0 answers
  1. Leslie
    Leslie avatar
    17 posts
    Member since:
    Jul 2010

    Posted 03 Oct 2011 Link to this post

    I am using the RadScheduleView version 2011.1.315.1040.  My custom appointment class overrides OnPropertyChanged where I set the Subject when some other properties change.  I have modified the template for the EditAppointmentDialog to add some new properties and have made the Subject read-only since it should be set by the OnPropertyChanged.  When I change the properties, the Subject should change accordingly.  However, the binding is not fired until the OK button is clicked.

    protected override void OnPropertyChanged(string propertyName)
        {
            base.OnPropertyChanged(propertyName);
            if (propertyName == "NumberOfPeople" || propertyName == "Start" || propertyName == "End")
            {
                Subject = string.Format("{0} people from {1} to {2}", NumberOfPeople, Start.TimeOfDay, End.TimeOfDay);
            }
        }

    Also, as part of the same scenario, if I resize the appointment in the timeline view, I would expect the Start/End properties to change and thus the Subject again to be updated.  I see PropertyChanged called for many different attributes, not just the Start/End, I see the subject being set, but the display and the tool tip are not updated.

    I would appreciate any help you can provide!

    Thank you,

    Leslie
  2. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 07 Oct 2011 Link to this post

    Hello Leslie,

    Thank you for  your question.

    To solve the issue I suggest you try the code below:
    protected override void OnPropertyChanged(string propertyName)
        {
            base.OnPropertyChanged(propertyName);
            if (propertyName == "NumberOfPeople" || propertyName == "Start" || propertyName == "End")
            {
    var isEditing = this.IsEditing;
    this.IsEditing = false;
     
                Subject = string.Format("{0} people from {1} to {2}", NumberOfPeople, Start.TimeOfDay, End.TimeOfDay);
    this.IsEditing = isEditing ;
            }
        }

    Regards,
    Rosi
    the Telerik team

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

  3. DevCraft banner
  4. Leslie
    Leslie avatar
    17 posts
    Member since:
    Jul 2010

    Posted 10 Oct 2011 Link to this post

    No, I am sorry, that seems to have no effect.  When I edit the appointment using the dialog, it still doesn't fire the property changed until I click the OK button.  When I drag the appointment, it shows me the results of the PREVIOUS drag operation.  For example, if I move it from 12 to 1, I see no change.  If I move it from 1 to 2, then it shows me 1.

    Any other thoughts?

    Leslie
  5. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 12 Oct 2011 Link to this post

    Hello Leslie,

    I suggest you send us running project illustrating the problem that we can test locally. We will review it and provide you with a solution.

    Kind regards,
    Rosi
    the Telerik team

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

  6. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 26 Oct 2011 Link to this post

    I am seeing the same behavior.  I have a custom Dialog, custom View Model with a property for AppointmentDialogViewModel, and a custom Appointment.

    When I assign the AppointmentDialogViewModel to the property, I execute this code:
                        
    _dialogViewModel.Occurrence.Appointment.PropertyChanged += Appointment_PropertyChanged;

    In the previous Q1 release of your dlls, this would allow me to trigger the following code any time the appointment changes.

    ConfirmCommand.RaiseCanExecuteChanged();

    That way I can validate the appointment and the confirm command anytime something changes on the appointment.

    I have just updated to the Q2 release, and the PropertyChanged event is no longer firing until the OK button is hit on the dialog (more specifically, _dialogViewModel.Confirm()).  Of course, if the appointment doesn't validate when the dialog is opened, then the OK button is never enabled.  I only found this by editing an appointment that already existed.

    Was this ever solved?  If so, what was the problem?

  7. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 27 Oct 2011 Link to this post

    Hi Michael,

    You can solve the problem by using a CustomAppointment and override the properties of the Appointment.By this way you can execute your code when a new value of the appointment's property is set:

    Example
    public class CustomAppointment : Appointment
        {

            public override string Subject
            {
                get
                {
                    return base.Subject;
                }
                set
                {
                    base.Subject = value;
                    //your code here
                }
            }
        }
    Hope this helps.

    All the best,
    Rosi
    the Telerik team

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

  8. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 27 Oct 2011 Link to this post

    I believe you missed my point.  In the Q1 build, I could attach an event handler to DialogViewModel.Occurrence.Appointment.PropertyChanged in my view model for the dialog and any time the appointment changed, it would trigger allowing me to check if the Confirm command can execute.

    Now, in the Q2 release, this event never gets hit until the DialogViewModel.Confirm is called.  It seems like the appointment being modified in the dialog is another appointment somewhere, then when Confirm is called, the changes get applied to Occurrence.Appointment.  I can't find this other appointment, and I need to be able to attach to it's property changed event in the dialog view model.

    The appointment can't tell the ConfirmCommand to invalidate itself because it doesn't have knowledge of the ConfirmCommand in the ViewModel.
  9. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 28 Oct 2011 Link to this post

    Hi,

    Yes, you do not have access to the ConfirmCommand in the ViewModel. However you can execute the CommandManager.InvalidateRequerySuggested(); method that will validate the CanExecute property of the Confirm command.

    To implement the task I suggest you inherit the class like this:
    public class CustomAppointment : Appointment
            {
                protected override void OnPropertyChanged(string propertyName)
                {
                    base.OnPropertyChanged(propertyName);
                    CommandManager.InvalidateRequerySuggested();
                }

            }

    Hope this helps.

    Regards,
    Rosi
    the Telerik team

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

  10. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 28 Oct 2011 Link to this post

    Hmm, I've got that already, but specifically so that the validation for the controls would work right:

            protected override void OnPropertyChanged(string propertyName)
            {
                base.OnPropertyChanged(propertyName);
                if (!propertyName.Equals("TimeError"))
                {
                    CommandManager.InvalidateRequerySuggested();
                }
            }

    The issue, I guess, is that I'm just using a standard System.Windows.Input.ICommand instead of the CommandManager for my ViewModel Confirm command.

    From what I've seen of the CommandManager (which admittedly, isn't a lot), I can't really use it for my situation.  Don't the methods for commands need to be static?  

    Can you post an example that uses the command manager for the Confirm command in a custom AppointmentDialog, with a custom ViewModel?  The only example I've seen like that used the standard ICommands for Confirm, and I haven't been successful attempting to use CommandManager.
  11. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 28 Oct 2011 Link to this post

    Hello,

    Here is an example of button that use Telerik Confirm command:
    <telerik:RadButton Margin="2" MinWidth="84" Command="telerik:WindowCommands.Confirm" />
    More detailed example you can find here.


    Kind regards,
    Rosi
    the Telerik team

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

  12. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 28 Oct 2011 Link to this post

    I've tried using that default command binding just to see if the OK button would enable or disable, and it still doesn't work.  In fact, the OK button never gets enabled when I have it setup that way.

    On top of that, your response or demo doesn't tell me how to actually implement the CommandManager in my custom ViewModel to intercept that Confirm command.

    The frustrating part is that this worked 3 days ago, before moving to Q2.  What changed in Q2 to break this?  It's a simple batch of code to tie a method to the PropertyChanged event for the Appointment.  Why isn't that being fired anymore?
  13. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 28 Oct 2011 Link to this post

    Hi Michael,

    There is no need to use the CommandManager by any other way except calling the InvalidateRequerySuggested method. This method will validate the CanExecute property of every command that is registered to it. Telerik Confirm command is registered to the CommandManager, so it should be validated too. Please find attached a sample example illustrating the behavior. When you enter End date that ends before the Start date the OK button will be disabled. When you correct the values the OK button will be enabled again.

    You are right that raising of PropertyChanged event is changed since Q1 version.We apologize for this and we will consider changing this behavior for the next version.

    Best wishes,
    Rosi
    the Telerik team

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

  14. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 28 Oct 2011 Link to this post

    I believe you are missing the point again.

    I have my own Confirm command code, and CanConfirmExecute code.  So I can't actually use your WindowCommands.Confirm unless I can attach that to my own command, in some way.  I only used that to test your theory that it should work, which it didn't, I can't ever get the OK button to enable.  I need my ViewModel to actually validate my CustomAppointment (because I need to check things that the appointment itself doesn't know about), hence why I have my own Confirm command.

    The example you gave was nothing more than changing the template of the dialog, yes, I would hope that would actually work.  Now, change the ViewModel of the dialog using it's Confirm command instead of the built in one, the DialogHost needs modified in order to give the EditDialog your custom ViewModel, and make a custom Appointment.  Then post that example, because just changing the template doesn't help me.

    I have done all of those things according to examples given by you guys on this forum, if needed, I could post the links to the threads.

    But according to your last paragraph, you are aware that it changed...is there no way now for the ViewModel to know when the appointment I'm editing changes???  No way at all?  I just need a solution to that, if I knew when it was changing, I could easily fix this.
  15. Leslie
    Leslie avatar
    17 posts
    Member since:
    Jul 2010

    Posted 29 Oct 2011 Link to this post

    I upgraded to 2011.2.920.1040 to see if this would solve my problem.  It did not.

    I have the following in my custom appointment class.  I tried it both with the isEditing and without.  I see it fire the PropertyChanged on the subject, but the binding in the appointment dialog is NOT updated and the new Subject is NOT displayed.

    private int _numberOfPeople;
    public int NumberOfPeople
    {
        get { return this.Storage<NeedAppointment>()._numberOfPeople; }
        set
        {
            var storage = this.Storage<NeedAppointment>();
            if (storage._numberOfPeople != value)
            {
                //var isEditing = this.IsEditing;
                //this.IsEditing = false;
                storage._numberOfPeople = value;
                SetSubject();
                //this.IsEditing = isEditing;
            }
        }
    }
  16. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 31 Oct 2011 Link to this post

    Yep, that is exactly what I'm seeing.  The OnPropertyChanged is getting hit, just not being shared with the dialog until Confirm is called.
  17. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 01 Nov 2011 Link to this post

    Hi ,

    I am sorry for the misunderstanding. I suggest you register your custom command via the Telerik CommandManager class .

    Example:
    CommandManager.RegisterClassCommandBinding(
                typeof(YourType), new CommandBinding(TestConfirmCommand, TestConfirmExecuted, TestConfirmCanExecute));

    If the problem still persist I suggest you send us sample running project or modify the one that I sent and send it to us. We will test it locally and provide you with a solution.

    As for the change - we introduced this change in Q2 SP1 release.We will do our best to improve it for the next release.

    Regards,
    Rosi
    the Telerik team

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

  18. Michael Lilly
    Michael Lilly avatar
    53 posts
    Member since:
    Apr 2010

    Posted 01 Nov 2011 Link to this post

    Yep, no change.  The CommandManager.InvalidateRequerySuggested() code gets hit in my custom appointment class, but the CanExecute code only gets hit at initial load of the window, never updates if the appointment changes.


    My only solution now is to keep the button enabled and do the CanConfirm code when they press the button.  Defeats the purpose of using commanding and I lose some great functionality around the CanConfirm, but it's the only solution that might actually work.

  19. Phil
    Phil avatar
    7 posts
    Member since:
    Feb 2009

    Posted 18 Dec 2011 Link to this post

    HI Michael, 

    I had this same problem, and found that if I provided an override for a different OnPropertyChanged, then it worked (at least in 2011Q2):

    protected override void OnPropertyChanged( string propertyName )
    {
        base.OnPropertyChanged( propertyName );
        CommandManager.InvalidateRequerySuggested();
    }
     
    protected override void OnPropertyChanged<TP>( Expression<Func<TP>> propertyExpression )
    {
        base.OnPropertyChanged( propertyExpression );
        CommandManager.InvalidateRequerySuggested();
    }

    The only problem I've had is that since we upgraded to 2011 Q3, we're now back at square 1! The InvalidateRequerySuggested() gets called happily, but the updates are not shared with the appointment edit template. Its like the template has somehow forgotten to register for the changes, despite the bindings being "TwoWay"

    Phil
  20. Gaetan
    Gaetan avatar
    4 posts
    Member since:
    Oct 2012

    Posted 24 May 2012 Link to this post

    Same problem... UP!
Back to Top
DevCraft banner