如何在RadPane的TitleTemplate中访问控件

时间:2012-08-09 10:26:50

标签: silverlight button telerik datatemplate gridsplitter

如何在RadPane的TitleTemplate中获取GridSplitter的句柄

<telerik:RadPane TitleTemplate="{StaticResource radPaneHeaderFormat}" ContextMenuTemplate="{x:Null}" CanDockInDocumentHost="False"  x:Name="radPane" Header="HeaderTitle" CanUserClose="False" CanFloat="False"    VerticalAlignment="Center" />

    <DataTemplate x:Key="radPaneHeaderFormat}"  ">
        <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="670" MaxWidth="678"/>
           <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="0.1*" />
            </Grid.ColumnDefinitions>

            <Button x:Name="ViewButton" Margin="0,0,5,0" Style="{StaticResource LeftArrowButtonStyle}" Click="ViewButton_Click" />
            <TextBlock Text="Summary" VerticalAlignment="Center" Grid.Column="1" />
            <sdk:GridSplitter Height="Auto"  Grid.Column="2" Name="HeaderSplitter" VerticalAlignment="Stretch" Style="{StaticResource newGridSplitterStyle}" />                               
             <TextBlock Text="Note"  Grid.Column="3" VerticalAlignment="Center"  Margin="3,0,0,0"/>
        </Grid>
    </DataTemplate>

任何人都可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

我不知道您要从哪里访问GridSplitter,但是,鉴于您有ButtonClick事件处理程序,我会告诉您如何可以在那里访问它:

    private void ViewButton_Click(object sender, RoutedEventArgs e)
    {
        var button = sender as Button;
        var panel = button.Parent as Panel;
        if (panel != null)
        {
            GridSplitter splitter = panel.Children.OfType<GridSplitter>().First();
            // do stuff with the GridSplitter...
        }
    }

如果您还没有行using System.Linq;,则需要添加一行。

在这种情况下,我正在利用按钮的Click事件处理程序向我们传递单击的按钮,ButtonGridSplitter具有相同的事实父节点。