I have a Silverlight application that uses a DataGrid. Inside this DataGrid, I have a DataTemplate, which is defined as follows:
<Grid x:Name="myGrid" Tag="{Binding}" Loaded="myGrid_Loaded"> <ItemsControl ItemsSource="{Binding MyItems}" Tag="{Binding}"> <ItemsControl.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Width="138"> <TextBlock Text="{Binding Type}" /> <TextBox x:Name="myTextBox" TextChanged="myTextBox_TextChanged" /> </StackPanel> </StackPanel> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Grid>
When a user enters text in a TextBox, I have an event (myTextBox_TextChanged) that should be fired at that moment. When this event is fired, I would like to get the ItemsControl element, which is the container for this TextBox. How to get this ItemControl from my event handler?
Please note: since the ItemsControl element is located in the DataTemplate DataGrid, I do not believe that I can just add x: Name and refer to it from my code. Or is there a way to do this?
Thanks!
source share