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

How to access control inside a DataTemplate from codebehind

2 Answers 1468 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dhanya
Top achievements
Rank 1
Dhanya asked on 13 Feb 2020, 06:29 AM

Hi,

I am using <telerik:GridViewDataColumn in which I have a DataTemplate. In this Datatemplate,I have my popup. I have written the below code in file say for example Sample.xaml. In the eventhandler 'PreviewTextInput' written in file Sample.xaml.cs, I need to set the 'BeadPlexNameInvalidPopup.IsOpen' property to true. Is there any way to access the popup in file Sample.xaml.cs?

Any small help would be appreciated!

 

    <telerik:GridViewDataColumn x:Name="GridviewColumn" Header="{x:Static res:Resources.BeadPlexName}"
                                    DataMemberBinding="{Binding Name}"
                                    Width="*"
                                    EditTriggers="CellClick">
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                     <DataTemplate>
                                        <Grid x:Name="Grid1">
                                            <TextBox x:Name="BeadPlexNameTextBox" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" MaxLength="70"
                                             PreviewTextInput="BeadPlexName_OnPreviewTextInput">
                                            </TextBox>
                                                <Popup Name="BeadPlexNameInvalidPopup" >
                                                    <ContentControl Template="{StaticResource InvalidCharPopupTemplate}" >
                                                    </ContentControl>
                                                </Popup>
                                            </Grid>
                                     </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>
                                </telerik:GridViewDataColumn>

2 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 13 Feb 2020, 08:13 AM

Hello Dhanya,

To achieve your requirement, you can get the parent Grid of the TextBox that fires the PreviewTextInput and then, get the Popup from its children collection. The code should look something like this:

private void BreadPlexNameTextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
{
	var tb = (TextBox)sender;
	var parentGrid = ParentOfTypeExtensions.ParentOfType<Grid>(tb);
	var popup = parentGrid.Children.OfType<Popup>().First();
}

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.
0
Dhanya
Top achievements
Rank 1
answered on 13 Feb 2020, 08:33 AM

Hi Martin,

It really worked!!! Tons of thanks!!! Especially for the quick response..

Tags
General Discussions
Asked by
Dhanya
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Dhanya
Top achievements
Rank 1
Share this question
or