Windows Phone Dev – Disabling the Tilt Animation on a ListView


I am working on a Windows Phone 8.1 Runtime app and have a ListView to display data on a detail page. The problem is that by default the tilt animation is enabled. This is not wanted because it gives visual feedback to the user that something should happen when the object is tapped.

To disable this behavior we need to create a copy of the default style of the ListView as follows:

Right click on the ListView in the designer and then select: Edit Additional Templates, Edit Generated Item Container (ItemContainerStyle), Edit a Copy…

A copy of the default style will be placed in your XAML.

Find the PointerUpThemeAnimation and PointerDownThemeAnimation Storyboards and remove them (or comment them out if you prefer):

     <VisualTransition From="Pressed"
             <PointerUpThemeAnimation Storyboard.TargetName="TiltContainer" />
     <VisualState x:Name="Normal" />
     <VisualState x:Name="Pressed">
            <PointerDownThemeAnimation Storyboard.TargetName="TiltContainer" />


Windows Phone Dev – Changing the rootFrame Background Color


In my Windows Phone 8 Runtime app I wanted to change the rootFrame background color from the default (black) to a custom color.

Here is the solution highlighted in my App.xaml.cs:

if (rootFrame == null)
    // Create a Frame to act as the navigation context and navigate to the first page
    rootFrame = new Frame();

    SolidColorBrush color = new SolidColorBrush();
    color.Color = (Windows.UI.ColorHelper.FromArgb(0xFF, 44, 50, 50));
    rootFrame.Background = color;

As you can see I used Windows.UI.Color.Helper.FromArgb to specify a custom color. If you want to use a predefined color just use color.Color = Windows.UI.Colors.Black; with the color of your choice on line 72.


Windows Phone Dev – Setting Style Properties for ListView


I wanted to style the background color for my ListView – so first I defined my style (ListViewBorder), in App.xaml:

<Style x:Key="ListViewBorder"
       <Setter Property="Template">
               <ControlTemplate TargetType="ListViewItem">
                   <Border Name="Border"
                       <ContentPresenter />

Then I bound my ListViewBorder to the ItemContainerStyle:

<Grid Grid.Row="1"
       <ListView x:Name="groupListView"
                 ItemsSource="{Binding AllGroups}"
                 ItemContainerStyle="{StaticResource ListViewBorder}"
                 ItemTemplate="{StaticResource RecipeGroupDataTemplate}"
                 Margin="0,10,0,0" />

Here’s the before and after results:


Custom ListView color



Windows Phone Dev – Making the Status Bar blend with your App


I’m working on a WinRT app for Windows Phone 8.1 and I wanted the app to blend in with the Status Bar more.

For this example I have added the highlighted code to my MainPage.xaml.cs:

        public MainPage()

            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += navigationHelper_LoadState;

            // Make Status Bar part of the screen



In my MainPage.xaml I have simply specified a border background around my first stackpanel:

&lt;!-- TitlePanel --&gt;
        &lt;Border Background=&quot;#0050EF&quot;&gt;
            &lt;StackPanel Grid.Row=&quot;0&quot;
                &lt;TextBlock x:Uid=&quot;RegionsPageHeader&quot;
                           Style=&quot;{StaticResource TitleTextBlockStyle}&quot;
                           SelectionChanged=&quot;TextBlock_SelectionChanged&quot; /&gt;

As you can see from the screenshot the Status bar and my textblock now share the same color.



Windows Phone Dev – XAML Background Alignment Grid


Some projects in Visual Studio have an alignment grid commented out in the MainPage.xaml.

Unfortunately the sample that I am working on did not have this code so I had to go looking for it:

<Image Source="/Assets/AlignmentGrid.png"
       IsHitTestVisible="False" />

This snippet needs to be inside the final </grid> tag on the page to work.

You will also need to put the AlignmentGrid.png in your assets folder.


Don’t forget to delete the .png and comment out (or delete) the code before uploading to the store!

Windows Phone Dev – XAML: Text Wrap and Text Trimming at the same time


Windows Phone typically uses a large font for headings, and this is great – until you have a lot of text.

By default headings will just run off the side of the screen, which for my app is not optimal. Turning on Text Wrapping is the next step – but that is not a great solution if you suddenly have three lines of very large text.

The solution would appear to be to simply use Text Wrapping and Text Trimming at the same time, but that doesn’t work until you specify the height of the textblock:

<TextBlock x:Name="AppCommand"
                       Text="{Binding Title}"
                       Style="{ThemeResource HeaderTextBlockStyle}" />

The MaxHeight property is something you will have to play around with depending on your needs, but as you can see I have limited my heading to two lines which is what I wanted to achieve:


Windows Phone Dev – Character Escape Sequences


I recently stumbled upon a list of c# character escape sequences here.

Escape sequences are needed because certain characters have special meanings within a literal string (and so cannot be used directly). For example, a single quote would need to be written as follows: \'

So I took a quick look at the list to see which ones would be useful working within a basic data-bound Windows Phone app sample.

The following escape sequences all functioned the same (which was expected):

  • \f – Form feed
  • \n – New line
  • \r – Carriage return

I have been in the habit of using \r\n in my apps for a new paragraph, but any combination of the above works.

The double quote escape sequence \" did not work but this special character sequence works fine instead: &quot;

The escape sequence that I liked the most was \t which is used for a horizontal tab. I wish I had known about this one a while back.

The other interesting one is \u for Unicode characters. With this you can, for example, open up Character Map, select any character and enter the four digit hex code for that character. \u00E6 will display a Latin small letter Ae. Very useful!