Completed
Last Updated: 28 Jun 2016 11:45 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 04 Feb 2014 12:52
Category: PropertyGrid
Type: Bug Report
2
FIX. RadPropertyGrid - application hangs when custom PropertyGridValueElement is used with RadTrackBarElement
Add a RadPropertyGrid and change its Dock property to Fill. Use the following code:

public partial class Form1 : Form
{
    RadPropertyStore _store;

    public Form1()
    {
        InitializeComponent();
        this.radPropertyGrid1.CreateItemElement += new CreatePropertyGridItemElementEventHandler(this.onCreateItemElement);
        _store = new RadPropertyStore();

        PropertyStoreItem barItem = new PropertyStoreItem(typeof(Int32), "TrackBar", 25);
        _store.Add(barItem);

        PropertyStoreItem sec = new PropertyStoreItem(typeof(bool), "Checkr", true);
        _store.Add(sec);

        this.radPropertyGrid1.SelectedObject = _store;
    }

    private void onCreateItemElement(object sender, CreatePropertyGridItemElementEventArgs e)
    {
        PropertyGridItem item = e.Item as PropertyGridItem;

        if (item != null)
        {
            if (item.Name == "TrackBar")
            {
                e.ItemElementType = typeof(TrackBarPropertyGridItem);
            }
        }
    }
}

public class TrackBarPropertyGridItem : PropertyGridItemElement
{
    protected override PropertyGridValueElement CreatePropertyGridValueElement()
    {
        return new CustomPropertyGridValueElement(); 
    }
}

public class CustomPropertyGridValueElement : PropertyGridValueElement
{
    RadTrackBarElement _trackbar;

    public RadTrackBarElement Trackbar
    {
        get
        {
            return this._trackbar;
        }
    }

    protected override void CreateChildElements()
    {
        base.CreateChildElements();

        _trackbar = new RadTrackBarElement();
        _trackbar.Minimum = 0;
        _trackbar.Maximum = 100;
       
        this.DrawText = false;
        this.Children.Add(_trackbar);
    }
}



When resizing the form, the applications hangs.

Workaround:

/// <summary>
    /// Track bar property grid element
    /// </summary>
    public class TrackBarPropertyGridItem : PropertyGridItemElement
    {
        class MyTrackBarElement : RadTrackBarElement
        {
            protected override void OnNotifyPropertyChanged(string propertyName)
            {
                if (propertyName == "TickOffSet" || propertyName == "ThumbSize")
                {
                    this.BodyElement.ScaleContainerElement.InvalidateMeasure();
                    this.BodyElement.IndicatorContainerElement.InvalidateMeasure();
                    return;
                }

                base.OnNotifyPropertyChanged(propertyName);
            }

            protected override Type ThemeEffectiveType
            {
                get
                {
                    return typeof(RadTrackBarElement);
                }
            }
        }

        /// <summary>
        /// The trackbar element to be displayed in the cell
        /// </summary>
        private RadTrackBarElement _trackbar;

        /// <summary>
        /// Accessor to the track bar element
        /// </summary>
        public RadTrackBarElement Trackbar
        {
            get { return _trackbar; }
        }

        /// <summary>
        /// Create child elements of the propertyGridItem
        /// </summary>
        protected override void CreateChildElements()
        {
            base.CreateChildElements();

            _trackbar = new MyTrackBarElement();
            _trackbar.Minimum = 0;
            _trackbar.Maximum = 100;
            _trackbar.ShowTicks = false;


            this.ValueElement.DrawText = false;
            this.ValueElement.Children.Add(this._trackbar);
        }

        /// <summary>
        /// Synchronise the value with property grid item
        /// </summary>
        public override void Synchronize()
        {
            base.Synchronize();

            PropertyGridItem item = this.Data as PropertyGridItem;

            this._trackbar.Value = (int)item.Value;
        }


        /// <summary>
        /// Add editor override
        /// </summary>
        /// <param name="editor">input editor</param>
        public override void AddEditor(IInputEditor editor)
        { }

        /// <summary>
        /// Remove editor override
        /// </summary>
        /// <param name="editor">input editor</param>
        public override void RemoveEditor(IInputEditor editor)
        { }

        /// <summary>
        /// Check if the item is comptable with trackbar editor
        /// </summary>
        /// <param name="data">item to check</param>
        /// <param name="context">context</param>
        /// <returns>true if compatible, false otherwise</returns>
        public override bool IsCompatible(PropertyGridItemBase data, object context)
        {
            PropertyGridItem item = data as PropertyGridItem;
            return (item != null && item.PropertyType == typeof(int));
        }

        /// <summary>
        /// Get the type of the property grid element
        /// </summary>
        protected override Type ThemeEffectiveType
        {
            get { return typeof(PropertyGridItemElement); }
        }
0 comments