我是 Windows Phone 8 开发的新手。我正在尝试在我的应用程序中创建类似日历的布局。为此,我在下面的 xaml 中使用了 Pivot 控件
<phone:Pivot x:Name="Piv" ItemsSource="{Binding Months}" Grid.Row="1" Margin="0,-10,0,0">
<phone:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Margin="0,0,0,0" Text="{Binding Name}" Height="70" FontSize="50"/>
</DataTemplate>
</phone:Pivot.HeaderTemplate>
<phone:Pivot.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,-20,0,0">
<Grid Margin="0,0,0,0" >
<!-- Header items goes here -->
</Grid>
<ItemsControl x:Name="CalendarControl" ItemsSource="{Binding Days}" ItemTemplate="{StaticResource HorizontalPivotTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid x:Name="CalGrid">
<!--Colums and rows for layout goes here-->
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
对于 Itemcontrol,我将两个 DataTemplates 定义为页面资源,如下所示。
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="VerticalPivotTemplate">
<Grid MinWidth="65" local:ItemsGridLayout.GridRow="{Binding Week}"
local:ItemsGridLayout.GridColumn="{Binding WeekDay}">
<Border BorderThickness="1" BorderBrush="White" >
<Grid Height="76">
<TextBlock VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding Day}" Style="{StaticResource PhoneTextLargeStyle}"/>
<TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Right" Text="{Binding DayMalayalam}" FontSize="16"/>
</Grid>
</Border>
</Grid>
</DataTemplate>
<DataTemplate x:Key="HorizontalPivotTemplate">
<Grid MinWidth="65" local:ItemsGridLayout.GridRow="{Binding Week}"
local:ItemsGridLayout.GridColumn="{Binding WeekDay}">
<Border BorderThickness="1" BorderBrush="White" >
<Grid Height="56">
<TextBlock VerticalAlignment="Top" HorizontalAlignment="Left" Text="{Binding Day}" Style="{StaticResource PhoneTextLargeStyle}"/>
<TextBlock VerticalAlignment="Bottom" HorizontalAlignment="Right" Text="{Binding DayMalayalam}" FontSize="16"/>
</Grid>
</Border>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
现在,我的要求是在这些模板之间进行选择,并在手机方向发生变化时将其分配给 ItemControl 的 ItemTemplate。为此,我使用了电话应用程序页面的 OrientationChanged 事件。
private void PhoneApplicationPage_OrientationChanged_1(object sender, OrientationChangedEventArgs e)
{
if (e.Orientation == PageOrientation.PortraitDown || e.Orientation == PageOrientation.PortraitUp)
{
//Assign VerticalPivotTemplate as CalendarControl's ItemTemplate
}
else
{
//Assign HorizontalPivotTemplate as CalendarControl's ItemTemplate
}
}
我不知道要写什么来达到我的要求。我无法在此处访问 CalendarControl ItemControl。请有人帮助我