Silverlight 在datatemplate中查找datacontext
我不是Silverlight专家,我正在与一个恼人的问题作斗争 我在网格中有一个Telerik Radrich文本框。此网格位于作为ItemsControl一部分的DataTemplate内。像这样:Silverlight 在datatemplate中查找datacontext,silverlight,Silverlight,我不是Silverlight专家,我正在与一个恼人的问题作斗争 我在网格中有一个Telerik Radrich文本框。此网格位于作为ItemsControl一部分的DataTemplate内。像这样: <ItemsControl Grid.Row="1" ItemsSource="{Binding MyCollection}"> <ItemsControl.ItemTemplate> <DataTemplate>
<ItemsControl Grid.Row="1" ItemsSource="{Binding MyCollection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<telerik:RadRichTextBox x:Name="_Editor" DocumentChanged="HandleditorDocumentChanged"/>
<Xaml:XamlDataProvider x:Name="xamlProvider" Xaml="{Binding Text}" RichTextBox="{Binding ElementName=_Editor}" />
<TextBox Grid.Row="1" Text="{Binding Text2}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
在DocumentChanges事件中,我希望访问DataTemplate的DataContext。我尝试将_编辑器的DataContext设置为{Binding},但在DataContext后面的代码中为null。
然后我想得到_编辑器的父级,即网格。其DataContext也为null,其父网格也为null
有什么想法吗?我想你要找的是DataContext代理。考虑这个例子: