How to hide a dependency property so that it cannot be set on the XAML

2k Views Asked by At

I m trying to customize the infragistics' xamdatagrid and i want to implement a functionality specific to my project like enabling summaries in a specific way and i want to disable the setting the summary option which is a dependency property from the XAML .

I m just getting started on the WPF and would like to check if this is possible ? All i want to accomplish here is to hide the existing dependency property so that the user cannot set it through XAML .

2

There are 2 best solutions below

1
On

You can't. There is no way you can hide the dependency property from the XAML not unless you are creating your own dependency property then just make it as a normal property. Since you mentioned you are customizing third party's control then no.

0
On

You can use EditorBrowsable attribute to hide dependency property from XAML. Please look into following sample.

 [EditorBrowsable(EditorBrowsableState.Never)]
    public int MyProperty
    {
        get { return (int)GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }

    // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MyPropertyProperty =
        DependencyProperty.Register("MyProperty", typeof(int), typeof(MyControl), new PropertyMetadata(0));

This attribute available under System.ComponentModel namespace.