在横向模式下隐藏全景标题[wp7]

时间:2010-11-27 21:19:46

标签: c# xaml silverlight windows-phone-7

我想在横向模式中隐藏标题<controls:Panorama Title="myTitle" Style="{StaticResource customStyle}">

我已经为它应用了自定义样式(下面的代码)并尝试执行此操作(基于自定义样式中的名称),但是我得到错误名称TitleLayer在当前上下文中不存在:< / p>

if ((e.Orientation == PageOrientation.LandscapeRight) || (e.Orientation == PageOrientation.LandscapeLeft))
{
    TitleLayer.Visibility = Visibility.Collapsed;
}

/////////////////查找额外代码///////////////////////

为此,我应用了自定义样式:

<phone:PhoneApplicationPage.Resources>
        <Style x:Key="customStyle" TargetType="controls:Panorama">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <controlsPrimitives:PanoramaPanel x:Name="panel"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="controls:Panorama">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <controlsPrimitives:PanningBackgroundLayer x:Name="BackgroundLayer" HorizontalAlignment="Left" Grid.RowSpan="2">
                                <Border x:Name="background" Background="{TemplateBinding Background}" CacheMode="BitmapCache"/>
                            </controlsPrimitives:PanningBackgroundLayer>
                            <controlsPrimitives:PanningTitleLayer x:Name="TitleLayer" CacheMode="BitmapCache" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" FontSize="187" FontFamily="{StaticResource PhoneFontFamilyLight}" HorizontalAlignment="Left" Margin="10,-76,0,9" Grid.Row="0"/>
                            <controlsPrimitives:PanningLayer x:Name="ItemsLayer" HorizontalAlignment="Left" Grid.Row="1">
                                <ItemsPresenter x:Name="items"/>
                            </controlsPrimitives:PanningLayer>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </phone:PhoneApplicationPage.Resources>

1 个答案:

答案 0 :(得分:2)

以下是隐藏全景标题的方法:

Grid grid = VisualTreeHelper.GetChild(panorama, 0) as Grid;
FrameworkElement titleLayer = grid.FindName("TitleLayer") as FrameworkElement;
titleLayer.Visibility = System.Windows.Visibility.Collapsed;

但是,我建议您阅读WP7设计指南。您似乎正在以不打算使用的方式使用Panorama。全景图仅用作肖像。通常,应用程序不应在全景图上有很多文本输入字段,因此不应支持滑出键盘的横向显示。