Turn ReadOnly on/off via ToggleButton on RadScheduleView

2 Answers 19 Views
ScheduleView
hhgm
Top achievements
Rank 1
Iron
Iron
hhgm asked on 20 Jan 2025, 11:26 PM | edited on 29 Jan 2025, 12:00 PM

Hi,

I have a ScheduleView where I want it to initially be readonly. But then open for edit by clicking a toggle button.

Right now I have added the ReadOnlyBehaviour... and I can see how I can remove it.. but adding it back when clicking out of Edit mode is not so clear.

I had an idea to add a bindable property to my readonlybehaviour like this:

    public class ScheduleViewReadOnlyBehaviour : ReadOnlyBehavior
    {
        private bool _isReadOnly;

        public static readonly DependencyProperty ReadOnlyProperty =
            DependencyProperty.Register(nameof(ReadOnly), typeof(bool), typeof(RadScheduleView),
                new PropertyMetadata(true, ReadOnlyPropertyChanged));

        private static void ReadOnlyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((ScheduleViewReadOnlyBehaviour)((RadScheduleView)d).ReadOnlyBehavior).ReadOnlyPropertyChanged((bool)e.NewValue);
        }

        private void ReadOnlyPropertyChanged(bool isReadOnly)
        {
            _isReadOnly = isReadOnly;
        }

        public bool ReadOnly
        {
            get { return (bool)GetValue(ReadOnlyProperty); }
            set { SetValue(ReadOnlyProperty, value); }
        }

        public override bool CanSaveAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence)
        {
            return false;
        }

        public override bool CanEditAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence)
        {
            return false;
        }

        public override bool CanDragAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence)
        {
            return false;
        }

        public override bool CanResizeAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence)
        {
            return false;
        }

        public override bool CanDeleteAppointment(IReadOnlySettings readOnlySettings, IOccurrence occurrence)
        {
            return false;
        }

        public override bool CanEditSlot(IReadOnlySettings readOnlySettings, Slot slot)
        {
            return false;
        }
    }

But keep ending up with the GetValue and SetValue methods not found.. obviously missing a point here. Would be a nice clean way of solving this problem.

 And yes, I am aware that I am currently not actually using the value being bound... I see that as the least of my issues.       

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 30 Jan 2025, 11:06 AM

Hello Hans-Henrik,

The DependencyProperty definition shows errors because the ReadOnlyBehavior is not a DependencyObject. You can create dependency properties only in classes that derive from DependencyObject. If you decide to go with the approach with a bool property in the custom ReadOnlyBehavior, then you should use a normal CLR property and manually assign it in the code-behind.

  public class ScheduleViewReadOnlyBehaviour : ReadOnlyBehavior
  {
      public bool ReadOnly { get; set; }

      // other code here
  }

 

private void MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "MyReadOnlyProperty")
    {
        this.readOnlyBehavior.ReadOnly = this.MyReadOnlyProperty
    }
}

Or alternatively, you can assign an remove the custom behavior when needed.

private readonly ScheduleViewReadOnlyBehaviour customReadOnlyBehavior = new ScheduleViewReadOnlyBehaviour();
private readonly ReadOnlyBehavior defaultReadOnlyBehavior = new ReadOnlyBehavior();

private void MyViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
	if (e.PropertyName == "MyReadOnlyProperty")
        {
		if(this.MyReadOnlyProperty)
		{
			this.scheduleView.ReadOnlyBehavior = customReadOnlyBehavior;
		}                else
		{
		        this.scheduleView.ReadOnlyBehavior = defaultReadOnlyBehavior();
		}
        }
}

 

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
hhgm
Top achievements
Rank 1
Iron
Iron
answered on 30 Jan 2025, 02:31 PM
Of course!  Thank you so much
Tags
ScheduleView
Asked by
hhgm
Top achievements
Rank 1
Iron
Iron
Answers by
Martin Ivanov
Telerik team
hhgm
Top achievements
Rank 1
Iron
Iron
Share this question
or