全景图像不随标题移动

时间:2014-04-07 19:00:52

标签: image xaml panorama-control

我在应用中为全景标题添加了一个图像。

XAML:

<phone:Panorama Title="MSFT Insider" Background="#FFD8D8D8" Foreground="Black" Style="{StaticResource PanoramaStyle1}">

PanoramaStyle1:

<phone:PhoneApplicationPage.Resources>
        <Style x:Key="PanoramaStyle1" TargetType="phone:Panorama">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <Primitives: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="phone:Panorama">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Primitives:PanningBackgroundLayer x:Name="BackgroundLayer" HorizontalAlignment="Left" Grid.RowSpan="2">
                                <Border x:Name="background" Background="{TemplateBinding Background}"/>
                            </Primitives:PanningBackgroundLayer>
                            <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal">
                                <Image Height="100" Source="Assets/Logos/Logo_transparente.png" Stretch="Fill" Margin="20,0,0,0" VerticalAlignment="Center"/>
                                <Primitives:PanningTitleLayer x:Name="TitleLayer" CharacterSpacing="-35" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" FontSize="80" FontFamily="{StaticResource PhoneFontFamilyLight}" HorizontalAlignment="Left" Height="128" VerticalAlignment="Center" Margin="10,0,0,0"/>
                            </StackPanel>
                            <Primitives:PanningLayer x:Name="ItemsLayer" HorizontalAlignment="Left" Grid.Row="1">
                                <ItemsPresenter x:Name="items"/>
                            </Primitives:PanningLayer>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

问题是当我向左或向右滑动时图像不随文本移动。

这就是我的意思:

Panorama image doesn't move

我能做些什么让它移动?我找到了任何搜索。

1 个答案:

答案 0 :(得分:1)

不要将StackPanel中的 PanningTitleLayer 与您的图像一起放置:

<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal">
     <Image Height="100" Source="Assets/Logos/Logo_transparente.png" Stretch="Fill" Margin="20,0,0,0" VerticalAlignment="Center"/>
     <Primitives:PanningTitleLayer x:Name="TitleLayer" CharacterSpacing="-35" ContentTemplate="{TemplateBinding TitleTemplate}" Content="{TemplateBinding Title}" FontSize="80" FontFamily="{StaticResource PhoneFontFamilyLight}" HorizontalAlignment="Left" Height="128" VerticalAlignment="Center" Margin="10,0,0,0"/>
</StackPanel>

你应该尝试将你的图像与PanningTitleLayer ContentPresenter 中的 TextBlock 一起放在StackPanel中,如下所示:

<Primitives:PanningTitleLayer x:Name="TitleLayer" CharacterSpacing="-35" ContentTemplate="{TemplateBinding TitleTemplate}"  FontSize="80" FontFamily="{StaticResource PhoneFontFamilyLight}" HorizontalAlignment="Left" Height="128" VerticalAlignment="Center" Margin="10,0,0,0">
    <ContentPresenter>
        <StackPanel Orientation="Horizontal">
            <Image Height="100" Source="Assets/Logos/Logo_transparente.png" Stretch="Fill" Margin="20,0,0,0" VerticalAlignment="Center"/>
            <TextBlock Text="{TemplateBinding Title}"/>
        </StackPanel>
    </ContentPresenter>
</Primitives:PanningTitleLayer>

请注意,<Primitives:PanningTitleLayer>不再定义Content属性。相反它有<ContentPresenter></ContentPresenter> TextBlock 现在被限制为Title(<TextBlock Text="{TemplateBinding Title}"/>

我希望这会有所帮助......