I'm using the LoopingSelector
as shown in this tutorial: WP7-LoopingSelector-in-depth--Part1. I just copied their XAML and C# code. I modified the XAML a bit to fit my layout but it's still similar to their tutorial though.
Here is my XAML code where I put the LoopingSelector:
<Grid>
<StackPanel Grid.Row="2">
<TextBlock Text="Countdown Time" HorizontalAlignment="Center"
FontSize="28" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<toolkitPrimitives:LoopingSelector x:Name="hSelector"
ItemMargin="2,3,3,2" ItemSize="100,100" />
<TextBlock Text=":" VerticalAlignment="Center" FontSize="64"
FontFamily="{StaticResource Digital7}"/>
<toolkitPrimitives:LoopingSelector x:Name="mSelector"
ItemMargin="2,3,3,2" ItemSize="100,100" />
<TextBlock Text="'" VerticalAlignment="Center" FontSize="64"
FontFamily="{StaticResource Digital7}"/>
<toolkitPrimitives:LoopingSelector x:Name="sSelector"
ItemMargin="2,3,3,2" ItemSize="100,100" />
</StackPanel>
</StackPanel>
</Grid>
where toolkitPrimitives
is defined as:
xmlns:toolkitPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls.Toolkit"
And here is what I did in the code behind:
this.hSelector.DataSource = new IntLoopingDataSource()
{
MinValue = 0,
MaxValue = 23,
SelectedItem = 0
};
this.mSelector.DataSource = new IntLoopingDataSource()
{
MinValue = 0,
MaxValue = 59,
SelectedItem = 1
};
this.sSelector.DataSource = new IntLoopingDataSource()
{
MinValue = 0,
MaxValue = 59,
SelectedItem = 0
};
I would have used TimePicker
instead however it doesn't support picking Second
. I need to pick Hour, Minute, and Second.
You need to set Width
and Height
and ItemSize
on the looping selector. This control doesn't handle cases without an absolute size very well. That's why it doesn't work in a StackPanel.
StackPanels provide an infinite width and height.
Normally controls are supposed to handle those cases, but being a primitive control, they've made the assumption that those values will be set.