How to bind visibility to custom appointment properties

3 posts, 0 answers
  1. Paul
    Paul avatar
    13 posts
    Member since:
    Nov 2010

    Posted 19 Apr 2012 Link to this post

    On the Appointment Detail form, I'm trying to bind visibility of a control to a custom appointment property. It works fine for the base properties, like IsAllDayEvent, but not for custom appointment properties. 

    I modified a Telerik sample project I found to demo the issue. 

    In my example, I have 2 checkboxes:
    - Is done?
    - IsAllDayEvent

    When checked, a label should be displayed to the right of each checkbox. 

            http://www.youtube.com/watch?v=funpvUMb6_Y&feature=youtu.be 

    You can see in the video that when the IsAllDayEvent value is toggled, the label's Visibility value changes immediately. 

    However, when the custom "IsDone" value is toggled the label's Visibility is not changed until the appointment is closing/saving.

    I would like controls bound to the values of custom properties to work like they do for the base IsAllDayEvent property. What am I missing?
     
    Thanks


    Here is the XAML I modified in the sample project. I'd be happy to zip the project and send it if that would help? 
     
        <StackPanel Orientation="Horizontal">
            <CheckBox Content="Is done?" 
    IsChecked="{Binding Occurrence.Appointment.IsDone, Mode=TwoWay}"/>

            <TextBlock Text="Appt Is DONE" 
    Visibility="{Binding Occurrence.Appointment.IsDone, Converter={StaticResource BooleanToVisibilityConverter}}" />
        </StackPanel>

        <StackPanel Orientation="Horizontal" >
            <CheckBox Content="IsAllDayEvent" 
    IsChecked="{Binding IsAllDayEvent, Mode=TwoWay}"/>

            <TextBlock Text="Appt Is All Day" 
    Visibility="{Binding IsAllDayEvent, Converter={StaticResource BooleanToVisibilityConverter}}"/>
        </StackPanel>


    This is the class w/ the custom IsDone property:

    public class Task : Appointment
    {
    private bool isDone;
    public bool IsDone
    {
    get
    {
    return this.Storage<Task>().isDone;
    }

    set
    {
    var storage = this.Storage<Task>();
    if (storage.isDone != value)
    {
    storage.isDone = value;
    this.OnPropertyChanged(() => this.IsDone);
    }
    }
    }

    public override IAppointment Copy()
    {
    var newAppointment = new Task();
    newAppointment.CopyFrom(this);
    return newAppointment;
    }

    public override void CopyFrom(IAppointment other)
    {
    var task = other as Task;
    if (task != null)
    {
    this.IsDone = task.IsDone;
    }

    base.CopyFrom(other);
    }
    }
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 23 Apr 2012 Link to this post

    Hello Daniel,

    Actually this is intended behavior - the PropertyChanged event is not fired when in editing mode, because we do not want the appointment view to be updated when the appointment is edited in the dialog window.  Note that IsAllDayEvent is a property of the ViewModel of the dialog, not of the appointment, that's why it works differently.

    However, you can workaround this behavior by overriding OnPropertyChanged method of the Task class like this:

    public class Task : Appointment
    {
        private bool isDone;
        public bool IsDone
        {
            get
            {
                return this.Storage<Task>().isDone;
            }
     
            set
            {
                var storage = this.Storage<Task>();
                if (storage.isDone != value)
                {
                    storage.isDone = value;
                    this.OnPropertyChanged(() => this.IsDone);
                }
            }
        }
     
        public override IAppointment Copy()
        {
            var newAppointment = new Task();
            newAppointment.CopyFrom(this);
            return newAppointment;
        }
     
        public override void CopyFrom(IAppointment other)
        {
            var task = other as Task;
            if (task != null)
            {
                this.IsDone = task.IsDone;
            }
     
            base.CopyFrom(other);
        }
     
        protected override void OnPropertyChanged(string propertyName)
        {
            var isEditing = this.IsEditing;
            this.IsEditing = false;
            base.OnPropertyChanged(propertyName);      
            this.IsEditing = IsEditing;
                 
        }
    }

    Hope this helps.

    All the best,
    Yana
    the Telerik team

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

  3. DevCraft banner
  4. Paul
    Paul avatar
    13 posts
    Member since:
    Nov 2010

    Posted 23 Apr 2012 Link to this post

    Thanks Yana. That worked.
Back to Top