<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chillijam.co.uk &#187; Windows Phone</title>
	<atom:link href="http://chillijam.co.uk/category/windows-phone/feed/" rel="self" type="application/rss+xml" />
	<link>http://chillijam.co.uk</link>
	<description></description>
	<lastBuildDate>Thu, 28 Jan 2021 10:32:11 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>WP7 Navigation Gotcha</title>
		<link>http://chillijam.co.uk/2012/02/16/wp7-navigation-gotcha/</link>
		<comments>http://chillijam.co.uk/2012/02/16/wp7-navigation-gotcha/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 15:28:13 +0000</pubDate>
		<dc:creator><![CDATA[Marc]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C# Snippets]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://chillijam.co.uk/?p=393</guid>
		<description><![CDATA[Navigating to a page, passing a key defined by a third party can present problems, but taking a little care over the way you pass the parameters can save a world of pain later.]]></description>
				<content:encoded><![CDATA[<p>This afternoon I discovered a bug in one of the apps I am working on.  It happens because the keys we use for navigation are provided in a third-party feed, and one of those keys contains a plus sign (&#8220;+&#8221;).  </p>
<p>This wasn&#8217;t immediately apparent as an issue, and we just navigated using </p>
<pre class="brush: csharp; title: ; notranslate">
NavigationService.Navigate(new Uri(&quot;/Views/TargetView.xaml?key=&quot; + myKeyValue, UriKind.Relative));
</pre>
<p>Unfortunately, this gets UrlDecoded on the receiving side as a sapce, so our key that started out being &#8220;text+text&#8221; was being resolved as &#8220;text text&#8221;.  When looking that value up in our tables the key was obviosuly not found and a NullReferenceException was thrown.</p>
<p>The fix was pretty simple, though.  We just had to UrlEncode the strong before we sent it, as follows.</p>
<pre class="brush: csharp; title: ; notranslate">
NavigationService.Navigate(new Uri(&quot;/Views/TargetView.xaml?key=&quot; + System.Net.HttpUtility.UrlEncode(myKeyValue), UriKind.Relative));
</pre>
<p>and all is good with the world again.</p>
]]></content:encoded>
			<wfw:commentRss>http://chillijam.co.uk/2012/02/16/wp7-navigation-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight Toolkit ExpanderView &#8211; Flat Objects</title>
		<link>http://chillijam.co.uk/2012/01/26/silverlight-toolkit-expanderview-flat-objects/</link>
		<comments>http://chillijam.co.uk/2012/01/26/silverlight-toolkit-expanderview-flat-objects/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 14:40:27 +0000</pubDate>
		<dc:creator><![CDATA[Marc]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C# Snippets]]></category>
		<category><![CDATA[Windows Phone]]></category>

		<guid isPermaLink="false">http://chillijam.co.uk/?p=382</guid>
		<description><![CDATA[Just one of many ways in which you can bind an ExpanderView control to a collection of simple objects.]]></description>
				<content:encoded><![CDATA[<p>Before anyone posts, I know this is not the intended usage of the control.  I did, however, have a requirement to show a list of simple objects and some of their properties in an expander view, so I&#8217;m going to explain one of many possible ways to do it.</p>
<p>My ViewModel contains an ObservableCollection&lt;ServiceAddOn&gt;, where my ServiceAddOn class looks like this.</p>
<pre class="brush: csharp; title: ; notranslate">
public class ServiceAddOn : INotifyPropertyChanged
{
    string name;
    string cost;
    DateTime startDate;
    DateTime expiryDate;
    // encapsulation for public access to the 4 locals
    // INotifyPropertyChanged implementation
}
</pre>
<p>Don&#8217;t worry about the encapsulation or INotifyPropertyChanged implementation &#8211; they  are as simple as it gets.</p>
<p>Now, I want to create an ListBox of ExpanderView controls that will display the information like this :</p>
<p><code><br />
My Item Name<br />
- Cost : £123.99<br />
- Start Date : 1/1/2012<br />
- Expiry Date : 1/1/2013<br />
Second Item<br />
ThirdItem<br />
</code></p>
<p>That is where the problems start.  As far as I can tell (with admittedly limited research into the issue) there is no way to bind to properties of an object in both the HeaderTemplate and the ItemTemplate &#8211; something needed to be done to expose these properties as a collection.  Since I was not able to change the inplementation of the ServiceAddOn class, I decided the best way would be to write a converter.  Before starting that, though, I needed a class to hold each of myt exposed properties.  It looks like this :</p>
<pre class="brush: csharp; title: ; notranslate">
public class ExposedProperty
{
    public string Key { get; set; }
    public string Value { get; set; }
}
</pre>
<p>Again, it is about as simple as it gets. <img src="http://chillijam.co.uk/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p>Now, the converter:</p>
<pre class="brush: csharp; title: ; notranslate">
public class ExposePropertyConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        ServiceAddOn obj = value as ServiceAddOn;
        if (null == obj) return null;
        ObservableCollection&lt;ExposedProperty&gt; values = new ObservableCollection&lt;ExposedProperty&gt;();
        values.Add(new ExposedProperty { Key = &quot;Cost&quot;, Value = obj.Cost });
        values.Add(new ExposedProperty { Key = &quot;Start Date&quot;, Value = obj.StartDate.Date.ToShortDateString() });
        values.Add(new ExposedProperty { Key = &quot;Expiry Date&quot;, Value = obj.ExpiryDate.Date.ToShortDateString() });

        return values;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
</pre>
<p>So now, it is just a case of a bit of plumbing&#8230;</p>
<p>Add the namespace reference to the XAML, and declare a converter instance</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;phone:PhoneApplicationPage 
    x:Class=&quot;MyExampleApp.MainPage&quot;
    ...snip...
    xmlns:conv=&quot;clr-namespace:MyExampleApp.Converters&quot;
    ...snip...
    &gt;
    &lt;phone:PhoneApplicationPage.Resources&gt;
        &lt;conv:ExposePropertyConverter x:Key=&quot;GetMyProperties&quot; /&gt;
    &lt;/phone:PhoneApplicationPage.Resources&gt;
</pre>
<p>and then wire up the Listbox / ExpanderView combo&#8230; (note tht my collection of ServiceAddOn objects is called &#8220;DisplayItems&#8221;)</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ListBox ItemsSource=&quot;{Binding DisplayItems}&quot;&gt;
    ...snip standard plumbing...
    &lt;ListBox.ItemTemplate&gt;
        &lt;DataTemplate&gt;
             &lt;toolkit:ExpanderView 
                 ItemsSource=&quot;{Binding Converter={StaticResource GetMyProperties}}&quot;
                 Header=&quot;{Binding}&quot;
                 NonExpandableHeader=&quot;{Binding}&quot;
                 Expander=&quot;{Binding}&quot;&gt;
                 &lt;toolkit:ExpanderView.HeaderTemplate&gt;
                     &lt;DataTemplate&gt;
                         &lt;TextBlock Text=&quot;{Binding Name}&quot; /&gt;
                     &lt;/DataTemplate&gt;
                 &lt;/toolkit:ExpanderView.HeaderTemplate&gt;
                 &lt;toolkit:ExpanderView.ItemTemplate&gt;
                     &lt;DataTemplate&gt;
                         &lt;TextBlock&gt;
                             &lt;Run Text=&quot;{Binding Key}&quot; /&gt;
                             &lt;Run Text=&quot; : &quot; /&gt;
                             &lt;Run Text=&quot;{Binding Value}&quot; /&gt;
                         &lt;/TextBlock&gt;
                     &lt;/DataTemplate&gt;
                 &lt;/toolkit:ExpanderView.ItemTemplate&gt;
             &lt;/toolkit:ExpanderView&gt;
        &lt;/DataTemplate&gt;
    &lt;/ListBox.ItemTemplate&gt;
&lt;/ListBox&gt;
</pre>
<p>The &#8220;magic&#8221; happens on line 6, where I bind the ItemsSource of the ExpanderView control to &#8220;{Binding Converter={StaticResource GetMyProperties}}&#8221;.</p>
<p>That&#8217;s it.</p>
<p>Next steps for this may be to make the Converter more generic, and possibly use reflection to get the properties instead of hard coding them, but for now this is good enough.</p>
<p>If you have any comments about a much simpler way to bind to flat, single-level objects in an ExpanderView control. I&#8217;d love to hear them.</p>
]]></content:encoded>
			<wfw:commentRss>http://chillijam.co.uk/2012/01/26/silverlight-toolkit-expanderview-flat-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alter a Pivot controls header template the easy way (WP7)</title>
		<link>http://chillijam.co.uk/2012/01/11/alter-a-pivot-controls-header-template-the-easy-way-wp7/</link>
		<comments>http://chillijam.co.uk/2012/01/11/alter-a-pivot-controls-header-template-the-easy-way-wp7/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 11:01:49 +0000</pubDate>
		<dc:creator><![CDATA[Marc]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C# Snippets]]></category>
		<category><![CDATA[Mango]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://chillijam.co.uk/?p=369</guid>
		<description><![CDATA[If you want to alter the template for a Windows Phone 7 pivot control&#8217;s header, the simplest way is as follows&#8230; Of course, all this example does is specifically set the colour used for the title and headers to black, but you can do (almost) whatever you like in those templates. Want to add an &#8230; <a href="http://chillijam.co.uk/2012/01/11/alter-a-pivot-controls-header-template-the-easy-way-wp7/" class="more-link">Continue reading <span class="screen-reader-text">Alter a Pivot controls header template the easy way (WP7)</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you want to alter the template for a Windows Phone 7 pivot control&#8217;s header, the simplest way is as follows&#8230;</p>
<pre class="brush: csharp; title: ; notranslate">
        &lt;controls:Pivot Title=&quot;Altered Styles&quot;&gt;
            &lt;controls:Pivot.HeaderTemplate&gt;  
                &lt;!-- This changes to look of the items headers --&gt;
                &lt;DataTemplate&gt;
                    &lt;TextBlock Text=&quot;{Binding}&quot; Foreground=&quot;Black&quot;/&gt;
                &lt;/DataTemplate&gt;
            &lt;/controls:Pivot.HeaderTemplate&gt;
            &lt;controls:Pivot.TitleTemplate&gt;
                &lt;!-- This changes to look of the pivot overall title --&gt;
                &lt;DataTemplate&gt;
                    &lt;TextBlock Text=&quot;{Binding}&quot; Foreground=&quot;Black&quot;/&gt;
                &lt;/DataTemplate&gt;
            &lt;/controls:Pivot.TitleTemplate&gt;
            &lt;controls:PivotItem Header=&quot;daily&quot;&gt;
                &lt;Grid/&gt;
            &lt;/controls:PivotItem&gt;
            &lt;controls:PivotItem Header=&quot;hourly&quot;&gt;
                &lt;Grid/&gt;
            &lt;/controls:PivotItem&gt;
        &lt;/controls:Pivot&gt;
</pre>
<p>Of course, all this example does is specifically set the colour used for the title and headers to black, but you can do (almost) whatever you like in those templates.  Want to add an image as a bullet?  Go for it.</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;controls:Pivot.HeaderTemplate&gt;
    &lt;DataTemplate&gt;
        &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
            &lt;Image Height=&quot;48&quot; Width=&quot;48&quot; Source=&quot;/MyBulletImage.png&quot; /&gt;
            &lt;TextBlock Text=&quot;{Binding}&quot; Foreground=&quot;Black&quot;/&gt;
        &lt;/StackPanel&gt;
    &lt;/DataTemplate&gt;
&lt;/controls:Pivot.HeaderTemplate&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://chillijam.co.uk/2012/01/11/alter-a-pivot-controls-header-template-the-easy-way-wp7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternating ListBox item background colours in WP7</title>
		<link>http://chillijam.co.uk/2012/01/11/alternating-listbox-item-background-colours-in-wp7/</link>
		<comments>http://chillijam.co.uk/2012/01/11/alternating-listbox-item-background-colours-in-wp7/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 10:34:42 +0000</pubDate>
		<dc:creator><![CDATA[Marc]]></dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C# Snippets]]></category>
		<category><![CDATA[Mango]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[WP7]]></category>

		<guid isPermaLink="false">http://chillijam.co.uk/?p=364</guid>
		<description><![CDATA[I had a requirement today to implement alternating row colours in a Windows Phone 7 ListBox. After a bit of frustration with searching and only finding answers tht said &#8220;You can&#8217;t do it&#8221;, or that you need to add a property on the model to bind the background to, I eventually hit upon a nugget &#8230; <a href="http://chillijam.co.uk/2012/01/11/alternating-listbox-item-background-colours-in-wp7/" class="more-link">Continue reading <span class="screen-reader-text">Alternating ListBox item background colours in WP7</span> <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I had a requirement today to implement alternating row colours in a Windows Phone 7 ListBox. After a bit of frustration with searching and only finding answers tht said &#8220;You can&#8217;t do it&#8221;, or that you need to add a property on the model to bind the background to, I eventually hit upon a nugget of common sense on <a href="http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/f9e9ce26-d576-45f8-a79d-762176695385" target="_blank">this page</a>.</p>
<p>Basically you need to create a converter class that will handle the alternation of backgrounds for you. It is ridiculously simple once you see it in action.</p>
<p><strong>Step 1 : Create the converter.</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public class AlternateRowColour : IValueConverter
{
bool isAlternate;
SolidColorBrush even = new SolidColorBrush(Colors.Transparent); // Set these two brushes to your alternating background colours.
SolidColorBrush odd = new SolidColorBrush(Color.FromArgb(255, 241, 241, 241));

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
isAlternate = !isAlternate;
return isAlternate ? even : odd ;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
</pre>
<p>Step 2 : Add the converter to the page</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;UserControl
 	...snip...
 	xmlns:conv=&quot;clr-namespace:MyApplication.Converters&quot; 
 	...snip...
 	&gt;
	&lt;UserControl.Resources&gt;
		&lt;conv:AlternateRowColour x:Key=&quot;RowColour&quot; /&gt;
	&lt;/UserControl.Resources&gt;
	...snip...
&lt;/UserControl&gt;
</pre>
<p>Step 3 : Bind to the ListBox</p>
<pre class="brush: csharp; title: ; notranslate">
&lt;ListBox ItemsSource=&quot;{Binding}&quot;&gt;
  &lt;ListBox.ItemTemplate&gt;
    &lt;DataTemplate&gt;
      &lt;Grid Background=&quot;{Binding Converter={StaticResource RowColour}}&quot;&gt;
        &lt;!-- layout XAML --&gt;
      &lt;/Grid&gt;
    &lt;/DataTemplate&gt;
  &lt;/ListBox.ItemTemplate&gt;
&lt;/ListBox&gt;				
</pre>
<p>And you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://chillijam.co.uk/2012/01/11/alternating-listbox-item-background-colours-in-wp7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
