IsReadOnly binding not working?

Grids for WPF Forum

Posted 16 years ago by Philipp Schmid
Version: 4.5.0485
Platform: .NET 3.5
Environment: Windows Vista (32-bit)
Avatar
I am trying to bind the IsReadOnly property of a PropertyGridPropertyItem like this:

<propgrid:PropertyGridPropertyItem ValueName="Quantity" 
   Value="{Binding Path=Quantity, UpdateSourceTrigger=PropertyChanged}" ValueType="{x:Type system:Single}"
   IsReadOnly="{Binding Path=IsFinal, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource IsFinalToReadOnlyConverter}}"
   Description="The desired quantity of this product." Category="General" />
The converter simply returns the NOT of the IsFinal boolean value:

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return !((bool)value);
        }
However, while this converter is called correctly when needed, the returned value seems to be ignored (IsReadOnly is always false).

Is this a known issue?

Philipp

Comments (11)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Philipp,

This was not a known issue, but I was able to reproduce it. The issue is that changes to the IsReadOnly property are not being properly reflected in the UI. The assumption was that the read-only state would not change. Regardless, this has been fixed for the next maintenance release so that changes to IsReadOnly will be reflected properly.


Actipro Software Support

Posted 16 years ago by Philipp Schmid
Avatar
Thanks for your reply.

Do you have an ETA for the next maintenance release?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Philipp,

We are hoping to get it out sometime this month, but it depends on when we get everything wrapped up and ready to be released.


Actipro Software Support

Posted 16 years ago by RredCat - Ukraine
Avatar
Is any workaround for this? Can I replace any template or etc.?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Until the maintenance release is out, you could subclass the PropertyGridPropertyItem. Your class would need to add a "changed" handler to the IsReadOnlyProperty. Then call OnPropertyChanged("IsReadOnly") in your handler.


Actipro Software Support

Posted 16 years ago by RredCat - Ukraine
Avatar
I don't understand your receipt. How can I know in subclass that property IsReadOnly was changed (When do I need to call my custom handler)?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The IsReadOnly is a dependency property, as defined in IsReadOnlyProperty, so in your derived class you can override the property metadata and add a "property value changed" handler. It's this handler that you would call OnPropertyChanged("IsReadOnly").


Actipro Software Support

Posted 16 years ago by RredCat - Ukraine
Avatar
I did like previous, but I have made a bug (in other part of code) and I couldn't see any effect... :) I have fixed it and all are working correct now.
Thanks, it helps.
Posted 16 years ago by RredCat - Ukraine
Avatar
hm.. I want to override NameTemplate of PropertyGridPropertyItem.

I write something like next:

<propgrid:PropertyGridPropertyItem.NameTemplate>
                    <DataTemplate>
                        <DockPanel LastChildFill="True" Margin="4,0,0,0" >
                            <CheckBox 
                                IsChecked="{Binding Path=IsReadOnly
                                    , RelativeSource={RelativeSource FindAncestor
                                    , AncestorType={x:Type propgrid:IPropertyDataAccessor}}}"/>
                            <TextBlock Margin="4,0,0,0"
                                Text="{Binding Path=ValueName
                                , RelativeSource={RelativeSource FindAncestor
                                , AncestorType={x:Type propgrid:IPropertyDataAccessor}}}" />
                        </DockPanel>
                    </DataTemplate>
                </propgrid:PropertyGridPropertyItem.NameTemplate>
So I have trouble. My check box isn't useful - binding raise exception (A TwoWay or OneWayToSource binding cannot work on the read-only property 'IsReadOnly' of type 'ActiproSoftware.Windows.Controls.PropertyGrid.Primitives.PropertyGridDataAccessorItem'.) if I use as source the PropertyGridPropertyItem it isn't work. Seems PropertyGridPropertyItem is only data-container for delivery data to real visual container(PropertyGridDataAccessorItem)

How can I walkround it?
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You are correct that the PropertyGridDataAccessorItem is used as a wrapper around the PropertyGridPropertyItem for display purposes. The PropertyGrid supports several data sources (e.g. SelectedObject(s), Properties, Items) all of which need to be displayed the same way. So the data layer items (such as the PropertyGridPropertyItem) all implement IPropertyDataAccessor, which the PropertyGridDataAccessor is capible of displaying.

In your example, you would need to access the underlying PropertyGridPropertyItem, which is available in the DataContext property of the PropertyGridDataAccessorItem. Something like this will work:
<propgrid:PropertyGridPropertyItem.NameTemplate>
    <DataTemplate>
        <DockPanel Margin="4,0,0,0">
            <CheckBox DockPanel.Dock="Left" IsChecked="{Binding Path=DataContext.IsReadOnly, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type propgrid:IPropertyDataAccessor}}}" />
            <TextBlock Margin="4,0,0,0" Text="{Binding Path=DisplayName, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type propgrid:IPropertyDataAccessor}}}" />
        </DockPanel>
    </DataTemplate>
</propgrid:PropertyGridPropertyItem.NameTemplate>
You will also need the latest maintenance release (v4.5.0487), otherwise changes to the IsReadOnly property will not be reflected in the UI.


Actipro Software Support

Posted 16 years ago by RredCat - Ukraine
Avatar
Thanks, it helps.
The latest build of this product (v24.1.3) was released 26 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.