Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Why is DependencyPropertyDescriptor for Visibility set to readonly and IsEnabled not

$
0
0

I created a "control group" attached property that should allow me to change the properties of a group of elements in code easily.  Basically I have a list of "Groups" defined by a string and adding the attached property to control adds it to the "Group".

Once registered I can then set a property on the group of controls to a value.  It works well for IsEnabled but when I tried to use it for Visibility it fails as it says the property is registered as readonly.

The code in the attached property for setting the property value is :

    Public Shared Sub ChangeProperty(DPProperty As DependencyProperty, controlGroup As String, value As Object)
        If ControlList Is Nothing Then Exit Sub
        For Each GC As GroupControl In ControlList
            If GC.GroupName = controlGroup Then
                Dim descriptor As DependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(DPProperty, GC.theControl.GetType())
                Dim theval = descriptor.GetValue(GC.theControl)
                descriptor.SetValue(GC.theControl, value)
                Dim xxx As Integer = 1
            End If
        Next
    End Sub

The XAML:

<Grid x:Name="OutPoint" Grid.Row="2" Grid.Column="3" Background="LightGreen" local:ControlGroupAP.GroupControl="InOut"

The calling code:

    Private Sub whatToEdit_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
        If whatToEdit.SelectedIndex = 0 Then
            ControlGroupAP.ChangeProperty(UIElement.IsVisibleProperty, "InOut", Visibility.Visible)
        Else
            ControlGroupAP.ChangeProperty(UIElement.IsVisibleProperty, "InOut", Visibility.Hidden)
        End If
    End Sub

The error I get from the attempt to change the property:

"'IsVisible' property was registered as read-only and cannot be modified without an authorization key."

Why would it think that IsEnabled is not readonly and Visibility is?

TIA

Lloyd Sheen


To add to the confusion , if I just try to use reflection I can access the property IsEnabled but not Visibility.  This makes no sense since in code you can set either property using code.

                Dim propv = GC.theControl.GetType().GetProperty("Visiblity")
                Dim prope = GC.theControl.GetType().GetProperty("IsEnabled")
The above code results in propv resulting in Nothing (Null) and prope resulting in a usable PropertyInfo.

Lloyd Sheen



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>