This is a migrated thread and some comments may be shown as answers.

How to bind visibility to custom appointment properties

2 Answers 346 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 19 Apr 2012, 06:57 PM
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 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 23 Apr 2012, 12:09 PM
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 >>

0
Paul
Top achievements
Rank 1
answered on 23 Apr 2012, 05:16 PM
Thanks Yana. That worked.
Tags
ScheduleView
Asked by
Paul
Top achievements
Rank 1
Answers by
Yana
Telerik team
Paul
Top achievements
Rank 1
Share this question
or