0

I am having a very hard time trying to access my Grid (listBoxGrid) from inside the ContentControl from code behind. Any help or pointers would be great!

Thanks Ryan

    <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>

I have tried

Grid myGrid = (Grid)Template.FindName("listBoxGrid", this);

But that doesn't seem to work.

4

1 回答 1

3

您只能使用 GetTemplateChild("PartName") 在 OnApplyTemplate() 方法覆盖中访问模板部分。

于 2010-12-13T19:08:11.320 回答