I am new to windows phone 8 development. I am trying to create a calendar like layout in my application. For that I used Pivot control as in the xaml below
<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>
For Itemcontrol, I have two DataTemplates defined as page resource as given below.
<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>
Now, my requirement is to choose between these templates and assign it to ItemControl's ItemTemplate when phone's orientation changes. For that I used OrientationChanged event of phone application page.
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
}
}
I don't know what to write in the event to achieve my requirement. I am unable to access CalendarControl ItemControl here. Please someone help me
I can't help noticing that you are just changing your grids width in DataTemplate, why dont you just use triggers to do that instead of changing the whole template..