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

Unable to access controls inside RadPropertyGrid

4 Answers 25 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Georg
Top achievements
Rank 1
Veteran
Georg asked on 12 Oct 2018, 03:33 PM

In my code-behind for the following XAML fragment, I would like to do "MyTextBox.Focus()", but MyTextBox is not accessible. Is there a way I can access it?

 

    <Grid>
        <telerik:RadPropertyGrid Item="{Binding}"
                                 RenderMode="Flat"
                                 AutoGeneratePropertyDefinitions="False"
                                 DescriptionPanelVisibility="Collapsed"
                                 SearchBoxVisibility="Collapsed"
                                 SortAndGroupButtonsVisibility="Collapsed"
                                 FieldIndicatorVisibility="Collapsed"
                                 Loaded="RadPropertyGrid_Loaded"
                                 LabelColumnWidth="150">
            <telerik:RadPropertyGrid.PropertyDefinitions>
                <telerik:PropertyDefinition DisplayName="Text"
                                            GroupName="Text Properties"
                                            OrderIndex="0">
                    <telerik:PropertyDefinition.EditorTemplate>
                        <DataTemplate>
                            <TextBox x:Name="MyTextBox"
                                     TextWrapping="Wrap"
                                     AcceptsReturn="True"
                                     AcceptsTab="True"
                                     Height="60"
                                     VerticalContentAlignment="Top"
                                     Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}"/>
                        </DataTemplate>
                    </telerik:PropertyDefinition.EditorTemplate>
                </telerik:PropertyDefinition>
            </telerik:RadPropertyGrid.PropertyDefinitions>
        </telerik:RadPropertyGrid>
    </Grid>

4 Answers, 1 is accepted

Sort by
0
Georg
Top achievements
Rank 1
Veteran
answered on 15 Oct 2018, 08:31 PM
I no longer need this functionality, although I'm still curious about it.
0
Stefan
Telerik team
answered on 17 Oct 2018, 10:49 AM
Hello Georg,

There is no out-of-the-box approach for accessing the TextBox, as it is within a DataTemplate. A possible approach would be to traverse the visual tree as discussed in the Find a WPF element inside DataTemplate in code-behind StackOverflow thread. I would not, however, recommend using such an approach. I would also like to clarify, that this is not specific for the UI for WPF RadPropertyGrid, but for the usage of DataTemplates in the framework in general.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ali
Top achievements
Rank 1
answered on 28 May 2019, 02:42 PM
Which argument must be sent to the function FindVisualChild because when I send the propertydefinition it make an error that property definition is not visual
0
Martin Ivanov
Telerik team
answered on 30 May 2019, 08:59 AM
Hello Ali,

The FindVisualChild method accepts a UI element. In this case, that is the RadPropertyGrid control. If you decide to use this approach (getting the DataTemplate element using code), I would recommend you to try the Telerik visual tree helper methods. You can read more about this in the UI for WPF help documentation.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PropertyGrid
Asked by
Georg
Top achievements
Rank 1
Veteran
Answers by
Georg
Top achievements
Rank 1
Veteran
Stefan
Telerik team
Ali
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or