Month: February 2013

Windows Phone Map control and ZoomLevel limits

ZoomLevel
The Oscars are over, I was playing with my application Earthquakes for Windows Phone and I noticed a bug in the map control. The problem is very simple, but I’d like to share it here with you Windows Phone developers so you don’t make the same mistake.
Like a lot of application that use the Map control, I have two buttons in the ApplicationBar that allow me to zoom in and zoom out.

ZoomLevelActions

So, when you use the Map control for Windows Phone 7 or Windows Phone 8, you can use the property ZoomLevel to zoom in or zoom out. On the click of the button I was simply increasing or decreasing the value without doing any control. I know that’s bad… Apparently, there is a limit for the zoom level that can be apply to the Map. Which is 1 to 19 for Windows Phone 7 and 1 to 20 for Windows Phone 8.

For Windows Phone 7 you can use the following code to change the ZoomLevel property:

private void BtZoomMore(object sender, EventArgs e)
{
   map.ZoomLevel = Math.Min(map.ZoomLevel + 1, 19);
}

private void BtZoomLess(object sender, EventArgs e)
{
   map.ZoomLevel = Math.Max(map.ZoomLevel - 1, 1);
}

And for Windows Phone 8:

private void BtZoomMore(object sender, EventArgs e)
{
   Map.ZoomLevel = Math.Min(Map.ZoomLevel + 1, 20);
}

private void BtZoomLess(object sender, EventArgs e)
{
   Map.ZoomLevel = Math.Max(Map.ZoomLevel - 1, 1);
}

Windows Azure outage on February 22, 2013

Azure SSL Outage

What a nice day in San Francisco after a week in Redmond, WA at the Microsoft headquarter for the Microsoft MVP Summit 2013.
On Friday, February 22, 2013 at 12:44 PM PST, the datacenters of the giant cloud service experienced a worldwide outage impacting the HTTPS traffic of the Storage service.

Azure Outage

1:30 PM PST, Microsoft identifies the issues. It comes from an expired SSL certificate. It seems Microsoft did not learn enough about the outage that happened during the leap day in 2012. Learn more about the service disruption of February 29th 2012.

Azure Outage

1:45 PM PST, Access Control, Service Bus, windowsazure.com and the WebSites services are also impacted by the SSL certificate expiration.

Azure Outage

2:15 PM PST, Microsoft start patching their testing environment.

AzureOutage4

3:45 PM PST, Microsoft start patching their production environment. It will take few more hours before a full recovery. The storage I use for my application Earthquakes was back online at around 9 PM PST. No one is 100% safe from this kind of problem, but this is the second outage due to a certificate. Let see if Microsoft will publish something to explain the details of the problem like they do every time something goes wrong.

AzureOutage5

Windows Azure Service Dashboard.

I updated my application Earthquakes for Windows Phone 8 with a back-end using Windows Azure and Mobiles Services. I hope I did not make this outage happened 😉
I’ll publish soon an update for both Windows Phone and Windows 8 to support the new features provided by the Azure back-end.

Using the AlternationIndex with a HeaderedItemsControl in XAML

DemoHeaderedItemsControlHeader

Today, I want to show you a very easy thing that you can use in your WPF applications. It’s so easy that I always forgot the syntax to do it… How to alternate the background color in a HeaderedItemsControl using only XAML code.

Let’s start to create the HeaderedItemsControl that will host a basic list of strings.

<HeaderedItemsControl ItemsSource="{Binding Items, ElementName=Window}">

    <HeaderedItemsControl.Header>
        <TextBlock Text="MESSAGE"
                   Margin="5,0" />
    </HeaderedItemsControl.Header>

    <HeaderedItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid x:Name="Grid">
                <TextBlock Text="{Binding}"
                           Margin="10" />
            </Grid>
        </DataTemplate>
    </HeaderedItemsControl.ItemTemplate>

    <HeaderedItemsControl.Template>
        <ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <Border Grid.Row="0"
                        BorderThickness="0,0,0,2"
                        BorderBrush="#FF535353" />

                <ContentPresenter Grid.Row="0"
                                  Margin="0,0,0,5"
                                  ContentSource="Header"
                                  HorizontalAlignment="Stretch" />

                <ItemsPresenter Grid.Row="1"
                                HorizontalAlignment="Stretch" />
            </Grid>
        </ControlTemplate>
    </HeaderedItemsControl.Template>

</HeaderedItemsControl>

This is the result of this very basic window:

DemoHeaderedItemsControlbasic

Now, in order to add the alternate background, we need to add the attribute AlternationCount to the HeaderedItemsControl. The value has to be the number of different index you need, in our example I’ll simply use two different backgrounds.

<HeaderedItemsControl AlternationCount="2"
                      ItemsSource="{Binding Items, ElementName=Window}">

Then, in order to change the background color of each row, I’ll use the triggers of the ItemTemplate to apply the new color to the Grid.

<HeaderedItemsControl.ItemTemplate>
    <DataTemplate>

        <Grid x:Name="Grid">
            <TextBlock Text="{Binding}"
                       Margin="10" />
        </Grid>

        <DataTemplate.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex"
                     Value="0">
                <Setter Property="Background"
                        Value="White"
                        TargetName="Grid" />
            </Trigger>
            <Trigger Property="ItemsControl.AlternationIndex"
                     Value="1">
                <Setter Property="Background"
                        Value="#FFF1F1F1"
                        TargetName="Grid" />
            </Trigger>
        </DataTemplate.Triggers>

    </DataTemplate>
</HeaderedItemsControl.ItemTemplate>

And the result is:

DemoHeaderedItemsControl

Continue reading