Gradient tab of PropertyGrid

Posted by: info on 4 April 2024, 11:31 pm EST

    • Post Options:
    • Link

    Posted 4 April 2024, 11:31 pm EST - Updated 4 April 2024, 11:36 pm EST

    Hello.

    How can I hide the Gradient tab?

    Thank you.

    C1.WPF.PropertyGrid.Ja 8.0.20233.688

  • Posted 7 April 2024, 11:19 pm EST - Updated 7 April 2024, 11:25 pm EST

    Hi Mikihiro,

    Currently, there is no direct way of hiding ‘Gradient’ tab. However, you can achieve the desired behavior by considering the workaround to modify the template of C1BrushEditor, that appears on clicking the drop-down button. This can be done by handling C1PropertyGrid’s PreviewMouseDown event as shown in the following code snippet;

    private void PropGrid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.OriginalSource is Rectangle rec)
        {
            if (rec.TemplatedParent is C1BrushPicker picker)
            {
                var brEdit = picker.Template.FindName("BrushEditor", picker) as C1BrushEditor;
                brEdit.Loaded += BrEdit_Loaded;
            }
            else if (rec.TemplatedParent is C1ToggleButton toggBtn)
            {
                var par = toggBtn.TemplatedParent;
                if (toggBtn.TemplatedParent is C1DropDownButton drpBtn)
                {
                    if (drpBtn.Content is C1BrushEditor brEdit)
                    {
                        brEdit.Loaded += BrEdit_Loaded;
                    }
                }
            }
        }
        else if (e.OriginalSource is C1CheckeredBorder chkBorder)
        {
            if (chkBorder.TemplatedParent is C1BrushPicker picker)
            {
                var brEdit = picker.Template.FindName("BrushEditor", picker) as C1BrushEditor;
                brEdit.Loaded += BrEdit_Loaded;
            }
        }
    }
    private void BrEdit_Loaded(object sender, RoutedEventArgs e)
    {
        if(sender is C1BrushEditor brushEdit)
        {
            var gradTab = brushEdit.Template.FindName("GradientBrushTab", brushEdit) as C1TabItem;
            if(gradTab != null)
            {
                gradTab.Visibility = Visibility.Collapsed;
            }
        }
    }

    Kindly refer to the attached sample for full implementation. See PropGridGradient.zip

    Otherwise, you can refer to the “Custom Editors” section of the same product sample application, to customize the editor as per your requirement.

    Hope this helps you.

    Thanks & Regards,

    Aastha

  • Posted 12 April 2024, 5:03 pm EST

    Thank you for your help.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels