ReadOnlyChanged

2 posts, 0 answers
  1. Dominik
    Dominik avatar
    59 posts
    Member since:
    Dec 2012

    Posted 28 Jan Link to this post

    Hi,

    I have a problem with RadRadioButton and RadToggleSwitch.

    I would like to change the look of the control depending on the ReadOnly state.

    But I can not find an event ReadOnlyChanged

    I also try to catch all property changes, but no event is registered when I change the ReadOnly.

    ((Telerik.WinControls.UI.RadRadioButtonElement)(x.GetChildAt(0))).RadPropertyChanged += ...
    ((Telerik.WinControls.UI.CheckBoxLayoutPanel)(x.GetChildAt(0).GetChildAt(1))).RadPropertyChanged += ...
    ((Telerik.WinControls.Layouts.ImageAndTextLayoutPanel)(x.GetChildAt(0).GetChildAt(1).GetChildAt(0))).RadPropertyChanged += ...
    ((Telerik.WinControls.UI.RadRadiomark)(x.GetChildAt(0).GetChildAt(1).GetChildAt(1))).RadPropertyChanged += ...
     
    ((Telerik.WinControls.UI.RadRadioButtonElement)(x.GetChildAt(0))).PropertyChanged += ...
    ((Telerik.WinControls.UI.CheckBoxLayoutPanel)(x.GetChildAt(0).GetChildAt(1))).PropertyChanged += ...
    ((Telerik.WinControls.Layouts.ImageAndTextLayoutPanel)(x.GetChildAt(0).GetChildAt(1).GetChildAt(0))).PropertyChanged += ...
    ((Telerik.WinControls.UI.RadRadiomark)(x.GetChildAt(0).GetChildAt(1).GetChildAt(1))).PropertyChanged += ...
     
    item.PropertyChanged += ...

  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 28 Jan Link to this post

    Hello Dominik,

    Thank you for writing.

    Indeed, there is no notification for changing the ReadOnly property of the mentioned controls. However, you can create your own property which will affect the ToggleSwitchElement.ReadOnly property and raise your custom event. You can find below a sample implementation of a custom RadToggleSwitch:
    public Form1()
    {
        InitializeComponent();
     
        this.radToggleSwitch1.ReadOnlyChanged += radToggleSwitch1_ReadOnlyChanged;
    }
     
    private void radToggleSwitch1_ReadOnlyChanged(object sender, ReadOnlyEventArgs e)
    {
        Console.WriteLine(e.ReadOnly);
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radToggleSwitch1.MyReadOnly = !this.radToggleSwitch1.MyReadOnly;
    }
     
    public class MyToggleSwitch : RadToggleSwitch
    {
        public event EventHandler<ReadOnlyEventArgs> ReadOnlyChanged;
     
        protected virtual void OnReadOnlyChanged(bool readOnly)
        {
            if (ReadOnlyChanged != null)
                ReadOnlyChanged(this, new ReadOnlyEventArgs(readOnly));
        }
         
        public bool MyReadOnly
        {
            get
            {
                return this.ToggleSwitchElement.ReadOnly;
            }
            set
            {
                this.ToggleSwitchElement.ReadOnly = value;
                OnReadOnlyChanged(this.ToggleSwitchElement.ReadOnly);
            }
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadToggleSwitch).FullName;
            }
        }
    }
     
    public class ReadOnlyEventArgs : EventArgs
    {
        public ReadOnlyEventArgs(bool readOnly)
        {
            ReadOnly = readOnly;
        }
     
        public bool ReadOnly { get; private set; }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top