标题模板和标题

时间:2013-11-17 11:53:47

标签: string xaml windows-phone-7 windows-phone-8 header

假设我们在wp7平台上有上述xaml:

<controls:Panorama x:Name="MainPanorama">
    <controls:PanoramaItem x:Name="Panorama1" TabIndex="1">
        <controls:PanoramaItem.Header>
            <StackPanel Orientation="Vertical"  Margin="12,70,0,-30">
                <TextBlock x:Name="Header1" Text="Downloader" FontSize="50" Margin="-5,-70,0,0" />
            </StackPanel>
        </controls:PanoramaItem.Header>

        ///////////////////////////////
        other xaml code like grids and other

    </controls:PanoramaItem>

    ///////////////////////////////
    other xaml code like PanoramaItems

</controls:Panorama>

如何获取Header1的TextBlock.Text(字符串),注意我想要动态的东西,因为我有很多PanoramaItems,我想动态获取每个PanoramaItem的标题,就像MainPanorama数组一样。

我试过这个:

PanoramaItem gen_panorama = MainPanorama.SelectedItem as PanoramaItem;
gen_panorama_head = Convert.ToString(gen_panorama.Header);

但是没有Header因为标题在每个PanoramaItem的模板中,我怎么能得到它?

1 个答案:

答案 0 :(得分:0)

我找到了带有'绑定'标题数据模板的解决方案!

<controls:Panorama x:Name="MainPanorama">
    <controls:Panorama.HeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical"  Margin="12,70,0,-30">
                TextBlock Text="{Binding}" FontSize="50" Margin="-12,-70,0,0" HorizontalAlignment="Left" Foreground="Black" />
            </StackPanel>
         </DataTemplate>
    </controls:Panorama.HeaderTemplate>

    <controls:PanoramaItem Header="Here any we want" x:Name="Panorama1" TabIndex="1">
    </controls:PanoramaItem>
</controls:Panorama>