Properties with Get only access show as editable?

Jun 16, 2010 at 5:48 PM

I have a few public get only properties, such as: public int Length { get; private set; } and when they are displayed in the grid they show up as editable. I can increment and decrement the value. It of course doesn't change the value but it also leaves the modified value in TextBoxView until I change the sort or reload the object. At which point it corrects the value.

I made a simple object to test the behavior:


    public class SimpleClass
    {
        public int PublicProperty { get; set;}

        protected int ProtectedProperty { get; set; }

        private int PrivateProperty { get; set; }

        public int GetOnly { get; private set; }

        public int SetOnly { set; private get; }
    }

I noted that when this object gets set on the Instance property the IsReadOnly property on the  WPG.Data.Property class is never accessed? So that makes sense why it always shows up as writable.

Anyone out there know where this property should be checked to make the int editor (or any editor for that matter) disable itself?. I spent a few minutes looking at the code but nowhere yet.

Thanks

Bryan

Jun 16, 2010 at 6:33 PM

Ok, well I seem to have figured out how to keep the Int stuff from being editable. Make the following changes:

To the WPGTemplates.xaml Files (one for VS and one for EB)

    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Int32}}">
        <typeeditors:IntegerTypeEditor Text="{Binding Path=Value}" IsReadOnly="{Binding Path=IsReadOnly}" Foreground="Black"></typeeditors:IntegerTypeEditor>
    </DataTemplate>

To the IntegerTypeEditor.xaml file

<Button ToolTip="Increase Value" Grid.Row="0" IsEnabled="{Binding Path=IsWriteable}" Command="{x:Static typeeditors:IntegerTypeEditor.UpCommand }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0">

and    

<Button ToolTip="Decrement Value" Grid.Row="1" IsEnabled="{Binding Path=IsWriteable}" Command="{x:Static typeeditors:IntegerTypeEditor.DownCommand }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0">

It looks like this might be an issue with enums and maybe others (but I have not gotten that far yet). I suspect it would require the same type of changes.

Bryan

 

Aug 6, 2010 at 10:29 AM

Hi,

 

I have come across this problem too.  I would additionaly like the ability to make the entire property grid read only regardless of the IsReadOnly attributes of the displayed properties. When in readonly mode, ideally many properties should be displayed using simple TextBlocks  rather than editors, comboboxes etc.

A possible approach would be to modify the data template selector to return a different data template depending on IsReadonly on the property and IsReadOnly on the main grid.  I'll let you know if I come up with something...

 

Dan

Dec 15, 2010 at 7:39 PM

Thanks for posting your changes. I'm only about 6 months into WPF, so finding this would have saved me a bit of work. I'm probably going to make some kind of converter so that I can just set the "Visibility" property on those buttons to Hidden since there is no point in displaying them for read-only properties.

This feels like such a basic feature to add to WPG, so I wonder why they haven't put that into the codebase. Perhaps the owners of this project are purposefully retarding it's progress so as to not compete with the commercial property grid offerings.

Coordinator
Jan 5, 2011 at 9:15 AM
BryanRoth wrote:

Ok, well I seem to have figured out how to keep the Int stuff from being editable. Make the following changes:

To the WPGTemplates.xaml Files (one for VS and one for EB)

    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Int32}}">
        <typeeditors:IntegerTypeEditor Text="{Binding Path=Value}" IsReadOnly="{Binding Path=IsReadOnly}" Foreground="Black"></typeeditors:IntegerTypeEditor>
    </DataTemplate>

To the IntegerTypeEditor.xaml file

<Button ToolTip="Increase Value" Grid.Row="0" IsEnabled="{Binding Path=IsWriteable}" Command="{x:Static typeeditors:IntegerTypeEditor.UpCommand }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0">

and    

<Button ToolTip="Decrement Value" Grid.Row="1" IsEnabled="{Binding Path=IsWriteable}" Command="{x:Static typeeditors:IntegerTypeEditor.DownCommand }" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0">

It looks like this might be an issue with enums and maybe others (but I have not gotten that far yet). I suspect it would require the same type of changes.

Bryan

 

 

Patch added to newest Version!