我很难从ContentControl里面的代码后面尝试访问我的Grid(listBoxGrid)。任何帮助或指针都会很棒!
由于 莱恩
<Style x:Key="ccTemplate" TargetType="{x:Type ContentControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContentControl}">
<Grid x:Name="listBoxGrid" TextOptions.TextFormattingMode="Display">
<Grid.RowDefinitions>
<RowDefinition Height="200*"/>
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid Grid.ColumnSpan="6" >
<ContentPresenter />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{x:Type control:ListBoxControl}" TargetType="{x:Type control:ListBoxControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentControl Style="{StaticResource ccTemplate}" x:Name="cc">
<telerikNavigation:RadTreeView
Name="mainList"
ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ItemsSource}"
ItemTemplate="{DynamicResource MainDataTemplate}"
ItemContainerStyle="{DynamicResource MainStyle}"
MinWidth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MinWidth}"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
BorderBrush="#FF00569F"
Background="{DynamicResource ListItemBackground}"
BorderThickness="1"
SelectionMode="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectionMode, FallbackValue=Single}"
IsDragDropEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDragDropEnabled, FallbackValue=False}"
IsDropPreviewLineEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsDropPreviewLineEnabled, FallbackValue=True}"
AllowDrop="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AllowDrop, FallbackValue=True}"
>
</telerikNavigation:RadTreeView>
</ContentControl>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我试过了
Grid myGrid = (Grid)Template.FindName("listBoxGrid", this);
但这似乎不起作用。
答案 0 :(得分:3)
您只能使用GetTemplateChild(“PartName”)访问OnApplyTemplate()方法覆盖中的模板部件。