TextBox.IsReadOnly doesn't work inside RadPropertyGrid.PropertyDefinitions

6 posts, 0 answers
  1. De
    De avatar
    16 posts
    Member since:
    Aug 2011

    Posted 02 Jun 2014 Link to this post

    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>
  2. De
    De avatar
    16 posts
    Member since:
    Aug 2011

    Posted 02 Jun 2014 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. De
    De avatar
    16 posts
    Member since:
    Aug 2011

    Posted 02 Jun 2014 in reply to De Link to this post

    // 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>
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 04 Jun 2014 Link to this post

    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.
     
  6. De
    De avatar
    16 posts
    Member since:
    Aug 2011

    Posted 04 Jun 2014 in reply to Ivan Ivanov Link to this post

    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).  
     
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 09 Jun 2014 Link to this post

    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.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready