This is a migrated thread and some comments may be shown as answers.

TextBox.IsReadOnly doesn't work inside RadPropertyGrid.PropertyDefinitions

5 Answers 267 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
De
Top achievements
Rank 1
De asked on 02 Jun 2014, 09:45 PM
One TextBox is outside of RadPropertyGrid and One TextBox is inside RadPropertyGrid.  The two are set to IsReadOnly=True, but only the outside one actually show read-only.

Version: Telerik.Windows.Controls.Data, Version=2013.3.1316.45.
Compiled with .Net 4.5
WPF app.
<
Window
    x:Class="PropGridTest.MainWindow"
    x:Name="ThisControl"
    Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
 
        <TextBox IsReadOnly="True" Text="Read-only" />
 
        <telerik:RadPropertyGrid
            Grid.Row="1"
            AutoGeneratePropertyDefinitions="False"
            Item="{Binding ElementName=ThisControl}">
            <telerik:RadPropertyGrid.PropertyDefinitions>
                <telerik:PropertyDefinition  
                    DisplayName="Prop 1"
                    GroupName="Group 1"
                    OrderIndex="0">
                    <telerik:PropertyDefinition.EditorTemplate>
                        <DataTemplate DataType="telerik:PropertyDefinition">
                            <TextBox HorizontalAlignment="Left" IsReadOnly="True" Text="Read-only" Width="100"/>
                        </DataTemplate>
                    </telerik:PropertyDefinition.EditorTemplate>
                </telerik:PropertyDefinition>
            </telerik:RadPropertyGrid.PropertyDefinitions>
            </telerik:RadPropertyGrid>
    </Grid>
</Window>

5 Answers, 1 is accepted

Sort by
0
De
Top achievements
Rank 1
answered on 02 Jun 2014, 10:56 PM
A few interesting findings (i.e. querks) about the RadPropertyGrid
1) if you need to set controls inside EditorTemplate to be read-only, the only way I found that works was to set PropertyDefinition.IsReadOnly.  Having TextBox's IsReadOnly doesn't work.
2) Binding with PropertyDefinition.IsReadOnly doesn't work.  I think it has something to do with timing of when the PropertyDefinition get constructed.  But if you have code behind (or custom behavior) iterates through RadPropertyGrid.PropertyDefinitions to set IsReadOnly, then it works.
3) If you don't set RadPropertyGrid's Item (assumed you specify AutoGenerateBindingPaths=False), all items are ...blank.  My hard lesson is always set Item property.
4) Remember that PropertyDefinition derives from DependencyObject, so its hierachical binding support is very limited.

0
De
Top achievements
Rank 1
answered on 02 Jun 2014, 11:59 PM
// An example that it DOESN'T WORK since DataContext doesn't flow inside PropertyDefinition (DataContext specified on Grid and the TextBox doesn't pick up).  Notes: model property has a inner property called Txt.
<telerik:PropertyDefinition.EditorTemplate>
         <DataTemplate >
                  <Grid DataContext="{Binding model}" >
                          <TextBox Text="{Binding Txt, Mode=TwoWay}" Width="100"/>
                   </Grid>
         </DataTemplate>
</telerik:PropertyDefinition.EditorTemplate>
 
// An example that it does WORK if specified explicitly  on the control itself (DataContext is now specified on the TextBox instead of Grid)
<telerik:PropertyDefinition.EditorTemplate>
         <DataTemplate >
                  <Grid >
                          <TextBox DataContext="{Binding model}" Text="{Binding Txt, Mode=TwoWay}" Width="100"/>
                   </Grid>
         </DataTemplate>
</telerik:PropertyDefinition.EditorTemplate>
0
Ivan Ivanov
Telerik team
answered on 04 Jun 2014, 08:36 AM
Hi,

Can you please clarify how do you bind PropertyDefinition's ReadOnly property. PropertyDefinition inherits from DependencyObject, but not from FrameworkElement. Thus, it does not have DataContext. Additionally, it is not present in the logical tree, so you cannot bind with ElementName, or RelativeSource. The recommended approach is to use explicitly set Source for the binding.

Regards,
Ivan Ivanov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
De
Top achievements
Rank 1
answered on 04 Jun 2014, 05:01 PM
On the first post, there is no binding.  TextBox's IsReadOnly is hard-coded in xaml.  Somehow, the TextBox's IsReadOnly property inside the EditorTemplate doesn't work.  

One of the big thing I want to understand is how 'Item' property flows to EditorTemplate.  
1) Would controls inside EditorTemplate expects ViewModel to flow through from RadPropertyGrid's Item property or  PropertyDefinition's Binding property?   If so, through what channels? (DataContext or some other ways)
2) Is it correct that all controls inside EditorTemplate must specify complete path for binding? (starting from whatever specified in RadPropertyGrid's Item property).  
 
0
Ivan Ivanov
Telerik team
answered on 09 Jun 2014, 03:19 PM
Hi,

Due to a popular feature request to support ReadOnly mode for custom editors, we have internal logic that binds their IsEnabled/ReadOnly. Thus, its previous value gets cleared. A simple workaround is to place the editor in some panel (panels does not support IsEnabled).
As for the other inquiries of yours, editors' DataContext is explicitly set to RadPropertyGrid.Item at runtime. So that, it is expected to set PropertyDefinition's Binding.Path to a property of the Item's type.

Regards,
Ivan Ivanov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
PropertyGrid
Asked by
De
Top achievements
Rank 1
Answers by
De
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Share this question
or