Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Layout Windows Phone-更改方向时更改布局_Layout_Windows Phone 8_Screen Orientation - Fatal编程技术网

Layout Windows Phone-更改方向时更改布局

Layout Windows Phone-更改方向时更改布局,layout,windows-phone-8,screen-orientation,Layout,Windows Phone 8,Screen Orientation,我正在构建一个WindowsPhone8应用程序,它使用Pivot控件为不同的用户显示给定日期的数据。每个数据透视项包含不同的用户 目前,我的应用程序只支持纵向,但我想构建对横向的支持。在此过程中,我希望每个数据透视项不再只显示一个日期的数据,而是显示整整一周的数据,从而显著改变布局 我的第一个方法是使用新的布局导航到一个新页面,但是在为此进行的一些研究中,我了解到,也许正确/最好的方法是更改数据模板。我假设它应该位于Pivot控件ItemTemplate上 然而,这一点,我一直无法让我的头左右

我正在构建一个WindowsPhone8应用程序,它使用Pivot控件为不同的用户显示给定日期的数据。每个数据透视项包含不同的用户

目前,我的应用程序只支持纵向,但我想构建对横向的支持。在此过程中,我希望每个数据透视项不再只显示一个日期的数据,而是显示整整一周的数据,从而显著改变布局

我的第一个方法是使用新的布局导航到一个新页面,但是在为此进行的一些研究中,我了解到,也许正确/最好的方法是更改数据模板。我假设它应该位于Pivot控件ItemTemplate上

然而,这一点,我一直无法让我的头左右,使工作。因此,我的问题是,当方向改变时(导航到新页面或更改DataTemplate),更改布局的最佳方法是什么?如果要更改Pivot控件的模板,应该如何做

编辑-当前轴控件的代码

<phone:Pivot x:Name="PivotPlatform" Title="DEMO" ItemsSource="{Binding PivotItems}" FontSize="13.333" >
   <phone:Pivot.HeaderTemplate>
       <DataTemplate>
           <TextBlock Text="{Binding Title}"/>
       </DataTemplate>
   </phone:Pivot.HeaderTemplate>
   <phone:Pivot.ItemTemplate>
       <DataTemplate>
           <!-- Controls omitted -->
       </DataTemplate>
   </phone:Pivot.ItemTemplate>
</phone:Pivot><?xml version="1.0" encoding="utf-8"?>


我认为我需要做的就是提取带有省略控件的DataTemplate,然后根据方向“仅仅”指定所需的DataTemplate。但是,我似乎找到了正确的语法,您可以在页面资源中为透视项创建新模板,然后处理layoutchange事件:

void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e){if (e.Orientation == PageOrientation.LandscapeLeft || e.Orientation == PageOrientation.LandscapeRight)
{
}
else 
{
}}

在页面资源中定义两个模板

<phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Key="DataTemplate1">
        <!--DEFINE TEMPLATE HERE-->
    </DataTemplate>
    <DataTemplate x:Key="DataTemplate2">
        <!--DEFINE TEMPLATE HERE-->
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>

那应该行

到目前为止你有什么代码?绝对不要导航到新页面-只需检测方向更改并应用不同的模板(假设您的数据保持不变)。明白了-我会找到一种不导航到新页面的方法:)我添加了代码,不过,为了提高可读性,我删除了布局本身。关于事件处理程序和检测方向,我同意您的看法。但是{}集合中有什么来指定模板呢?谢谢igrali-我只需要在
    <phone:Pivot x:Name="PivotPlatform"
                 Title="DEMO"
                 FontSize="13.333"
                 ItemsSource="{Binding PivotItems}">
        <phone:Pivot.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Title}" />
            </DataTemplate>
        </phone:Pivot.HeaderTemplate>
    </phone:Pivot>
<phone:PhoneApplicationPage ....
                        OrientationChanged="PhoneApplicationPage_OrientationChanged"
                        ....>
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
    if (e.Orientation == PageOrientation.PortraitDown || e.Orientation == PageOrientation.PortraitUp)
    {
        PivotPlatform.ItemTemplate = this.Resources["DataTemplate1"] as DataTemplate;
    }
    else
    {
        PivotPlatform.ItemTemplate = this.Resources["DataTemplate2"] as DataTemplate;
    }
}