<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>slimCODE</title>
	<atom:link href="https://blog.slimcode.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.slimcode.com</link>
	<description>simple SOLUTIONS</description>
	<lastBuildDate>Sat, 10 Mar 2018 02:45:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.slimcode.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://secure.gravatar.com/blavatar/9abafe5ae3f3ef15cff732d2a50f7dfb?s=96&#038;d=https%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>slimCODE</title>
		<link>https://blog.slimcode.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://blog.slimcode.com/osd.xml" title="slimCODE" />
	<atom:link rel='hub' href='https://blog.slimcode.com/?pushpress=hub'/>
	<item>
		<title>Late-binding, Bing Maps and Pushpins with an unknown position</title>
		<link>https://blog.slimcode.com/2011/03/28/late-binding-bing-maps-and-pushpins-with-an-unknown-position/</link>
		<comments>https://blog.slimcode.com/2011/03/28/late-binding-bing-maps-and-pushpins-with-an-unknown-position/#comments</comments>
		<pubDate>Mon, 28 Mar 2011 17:30:30 +0000</pubDate>
		<dc:creator><![CDATA[slimcode]]></dc:creator>
				<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Bing Maps]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://slimcode.wordpress.com/2011/03/28/late-binding-bing-maps-and-pushpins-with-an-unknown-position/</guid>
		<description><![CDATA[It seems the Bing Maps controls for Windows Phone 7 have a little problem when you use late-binding (setting the data context in the Loaded event, for example) and you have a Pushpin with a Location set to GeoCoordinate.Unknown. For example, take this Pushpin declaration: &#60;map:Pushpin Location=&#34;{Binding UserPosition}&#34; Content=&#34;you&#34; Visibility=&#34;{Binding UserPosition, Converter={StaticResource GeoCoordinateVisibilityConverter}}&#34; /&#62; &#160; [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>It seems the <a href="http://msdn.microsoft.com/en-us/library/ff941096(VS.92).aspx" target="_blank">Bing Maps controls for Windows Phone 7</a> have a little problem when you use late-binding (setting the data context in the Loaded event, for example) and you have a <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.maps.pushpin(v=VS.92).aspx" target="_blank">Pushpin</a> with a <a href="http://msdn.microsoft.com/en-us/library/microsoft.phone.controls.maps.pushpin.location(v=VS.92).aspx" target="_blank">Location</a> set to <a href="http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinate.unknown(v=VS.92).aspx" target="_blank">GeoCoordinate.Unknown</a>. For example, take this Pushpin declaration:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a811a06d-9a46-40f3-b3b9-f5235abce182" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;max-height:500px;overflow:auto;">
<ol style="background:#001122;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">map</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">Pushpin Location</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">Binding UserPosition}</span><span style="color:#c0c0c0;">&quot;</span><span style="color:#ffffff;"> Content</span><span style="color:#0080c0;">=</span><span style="color:#c0c0c0;">&quot;you&quot;</span><span style="color:#ffffff;"> Visibility</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">Binding UserPosition</span><span style="color:#0080c0;">,</span><span style="color:#ffffff;"> Converter</span><span style="color:#0080c0;">={</span><span style="color:#ffffff;">StaticResource GeoCoordinateVisibilityConverter}}</span><span style="color:#c0c0c0;">&quot;</span><span style="color:#0080c0;"> /&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>Even if you change the pushpin’s visibility to Collapsed for unknown locations, you end up with an ugly exception:</p>
<blockquote>
<p>System.InvalidOperationException occurred:      <br />&#160; Message=UIElement.Arrange(finalRect) cannot be called with Infinite or NaN values in finalRect.       </p>
</blockquote>
<p style="margin-right:0;" dir="ltr">Well, that’s great info, right? The workaround I found was to insert that pushpin in a layer, and collapse the layer for the same criteria:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:491526d6-3573-4ac9-9f27-994c078e8171" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;max-height:500px;overflow:auto;">
<ol style="background:#001122;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#bff9d2;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">map</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">MapLayer Visibility</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">Binding UserPosition</span><span style="color:#0080c0;">,</span><span style="color:#ffffff;"> Converter</span><span style="color:#0080c0;">={</span><span style="color:#ffffff;">StaticResource GeoCoordinateVisibilityConverter}}</span><span style="color:#c0c0c0;">&quot;</span><span style="color:#0080c0;">&gt;</span></li>
<li style="background:#0c0516;">    <span style="color:#bff9d2;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">map</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">Pushpin Location</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">Binding UserPosition}</span><span style="color:#c0c0c0;">&quot;</span><span style="color:#ffffff;"> Content</span><span style="color:#0080c0;">=</span><span style="color:#c0c0c0;">&quot;you&quot;</span><span style="color:#0080c0;"> /&gt;</span></li>
<li><span style="color:#bff9d2;"></span><span style="color:#0080c0;">&lt;/</span><span style="color:#ffffff;">map</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">MapLayer</span><span style="color:#0080c0;">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>A little overhead, but it works.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.slimcode.com/2011/03/28/late-binding-bing-maps-and-pushpins-with-an-unknown-position/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/45020afc2c207a7de30a5a92c9592806?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slimcode</media:title>
		</media:content>
	</item>
		<item>
		<title>GeoTrax missing link &#8211; Do it yourself!</title>
		<link>https://blog.slimcode.com/2011/02/07/geotrax-missing-link-do-it-yourself/</link>
		<comments>https://blog.slimcode.com/2011/02/07/geotrax-missing-link-do-it-yourself/#respond</comments>
		<pubDate>Tue, 08 Feb 2011 01:13:05 +0000</pubDate>
		<dc:creator><![CDATA[slimcode]]></dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Do it yourself]]></category>
		<category><![CDATA[GeoTrax]]></category>

		<guid isPermaLink="false">http://slimcode.wordpress.com/2011/02/07/geotrax-missing-link-do-it-yourself/</guid>
		<description><![CDATA[With the two GeoTrax sets we have, I often get to a point where I’m missing one or two half-length straight tracks. I’ve looked at acquiring them on eBay et al, but it becomes very expensive for only those two pieces. Today, I realized that the missing part was barely longer than the length of [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;float:left;padding-top:0;border-width:0;margin:0 10px 0 0;" title="WP_000105" border="0" alt="WP_000105" align="left" src="https://slimcode.files.wordpress.com/2011/02/wp_000105.jpg?w=244&#038;h=184" width="244" height="184" />With the <a href="http://www.fisher-price.com/fp.aspx?st=5754&amp;e=product&amp;pid=41314" target="_blank">two GeoTrax</a> <a href="http://www.fisher-price.com/fp.aspx?st=5754&amp;e=product&amp;pid=41310" target="_blank">sets we have</a>, I often get to a point where I’m missing one or two half-length straight tracks. I’ve looked at acquiring them on eBay et al, but it becomes very expensive for only those two pieces. Today, I realized that the missing part was barely longer than the length of a clothespin. Hmmm, interesting. It turns out that wagons only need one side of the rails to be flat (the inner part). And the small missing gap isn’t a problem, the crossing track already has gaps and it doesn’t affect the wagons. Could I split a wooden pin in two and use these parts as rails?</p>
<p>Yes, quite easily!</p>
<p>  </p>
<p>First, you take a half-length track and draw the contour on cardboard. You cut out the piece, making sure to remove the pen width too, else it will be difficult to fit into the real pieces. You might have to clue together two layers of cardboard if its too thin. The cardboard and the pin’s width must equal the original rail’s thickness. In my case, I cut two pieces and glued them together.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000097" border="0" alt="WP_000097" src="https://slimcode.files.wordpress.com/2011/02/wp_000097.jpg?w=184&#038;h=244" width="184" height="244" />&#160;<img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000098" border="0" alt="WP_000098" src="https://slimcode.files.wordpress.com/2011/02/wp_000098.jpg?w=184&#038;h=244" width="184" height="244" />&#160;<img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000099" border="0" alt="WP_000099" src="https://slimcode.files.wordpress.com/2011/02/wp_000099.jpg?w=184&#038;h=244" width="184" height="244" /></p>
<p>Then you split the clothespin in two, discarding the spring. I measured the inner distance between the rails on the original track. It’s 30 mm or 1” 3/16. You draw lines on the cardboard piece for that distance, making sure these are centered. In my case, the lines were 17 mm from the edge (5/8”), though it was more like 16 mm on the original piece.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000100" border="0" alt="WP_000100" src="https://slimcode.files.wordpress.com/2011/02/wp_000100.jpg?w=244&#038;h=184" width="244" height="184" />&#160;<img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000101" border="0" alt="WP_000101" src="https://slimcode.files.wordpress.com/2011/02/wp_000101.jpg?w=244&#038;h=184" width="244" height="184" /></p>
<p>You put some glue on the edge of each wood piece, and place them carefully, so that their flat side lies on the line, the uneven side pointing outside. Once the second piece is placed, take the ruler before the glue dries, and adjust it so you get 30 mm (or 31 mm, better more than less) between the pieces.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000102" border="0" alt="WP_000102" src="https://slimcode.files.wordpress.com/2011/02/wp_000102.jpg?w=244&#038;h=184" width="244" height="184" /></p>
<p>Let it dry a few minutes. You now have a nice half-length track replacement part. Sure, it doesn’t clip into other pieces, it just slides into them. But most track layouts stay in place even with such a weakest link.</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000103" border="0" alt="WP_000103" src="https://slimcode.files.wordpress.com/2011/02/wp_000103.jpg?w=244&#038;h=184" width="244" height="184" />&#160;<img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000104" border="0" alt="WP_000104" src="https://slimcode.files.wordpress.com/2011/02/wp_000104.jpg?w=244&#038;h=184" width="244" height="184" /></p>
<p>You can now make those crossing tracks patterns you couldn’t with only two half-length rails. Hurray!</p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000106" border="0" alt="WP_000106" src="https://slimcode.files.wordpress.com/2011/02/wp_000106.jpg?w=364&#038;h=274" width="364" height="274" /></p>
<p><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="WP_000107" border="0" alt="WP_000107" src="https://slimcode.files.wordpress.com/2011/02/wp_000107.jpg?w=364&#038;h=484" width="364" height="484" /></p>
]]></content:encoded>
			<wfw:commentRss>https://blog.slimcode.com/2011/02/07/geotrax-missing-link-do-it-yourself/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/45020afc2c207a7de30a5a92c9592806?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slimcode</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000105.jpg" medium="image">
			<media:title type="html">WP_000105</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000097.jpg" medium="image">
			<media:title type="html">WP_000097</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000098.jpg" medium="image">
			<media:title type="html">WP_000098</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000099.jpg" medium="image">
			<media:title type="html">WP_000099</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000100.jpg" medium="image">
			<media:title type="html">WP_000100</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000101.jpg" medium="image">
			<media:title type="html">WP_000101</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000102.jpg" medium="image">
			<media:title type="html">WP_000102</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000103.jpg" medium="image">
			<media:title type="html">WP_000103</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000104.jpg" medium="image">
			<media:title type="html">WP_000104</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000106.jpg" medium="image">
			<media:title type="html">WP_000106</media:title>
		</media:content>

		<media:content url="http://slimcode.files.wordpress.com/2011/02/wp_000107.jpg" medium="image">
			<media:title type="html">WP_000107</media:title>
		</media:content>
	</item>
		<item>
		<title>Detect when a ListBox scrolls to its end (WP7)</title>
		<link>https://blog.slimcode.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/</link>
		<comments>https://blog.slimcode.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 14:11:14 +0000</pubDate>
		<dc:creator><![CDATA[slimcode]]></dc:creator>
				<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Infinite scrolling]]></category>
		<category><![CDATA[ListBox]]></category>
		<category><![CDATA[wp7]]></category>

		<guid isPermaLink="false">http://slimcode.wordpress.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/</guid>
		<description><![CDATA[I wanted to fetch and add new items to a ListBox when it scrolls to its end, to reproduce infinite scrolling. Fellow tweep @GaryGJohnson pointed me to the ScrollViewer’s VerticalOffset, ExtentHeight and ViewportHeight, which would give me all the maths I needed. Unfortunately, there it no scrolling events available, either on the ListBox or the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I wanted to fetch and add new items to a ListBox when it scrolls to its end, to reproduce infinite scrolling.</p>
<p>Fellow tweep <a href="http://twitter.com/GaryGJohnson" target="_blank">@GaryGJohnson</a> pointed me to the ScrollViewer’s VerticalOffset, ExtentHeight and ViewportHeight, which would give me all the maths I needed.</p>
<p>Unfortunately, there it no scrolling events available, either on the ListBox or the inner ScrollViewer. From what I understand, I could have received change notifications directly from the ScrollViewer’s VerticalOffset property if I were to work with SL4, but not with SL3 on Windows Phone 7. My friend <a href="http://twitter.com/Jak3b0" target="_blank">Jacques</a> came to the rescue! He suggested I create myself a custom DependencyProperty with a changed notification, and bind it to the ScrollViewer’s VerticalOffset.</p>
<p>&#160;</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b21feafc-9b11-49b8-b6ae-4bdec8bc5459" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">My ListBox declaration</div>
<div style="background-color:#001122;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#bff9d2;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">ListBox x</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">Name</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;businessesListBox&quot; </span><br />          <span style="color:#ffffff;">ItemsSource</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">Binding Listings}</span><span style="color:#ffffff;">&quot; </span><br />          <span style="color:#ffffff;">ItemTemplate</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">StaticResource ListingItemTemplate}</span><span style="color:#ffffff;">&quot; </span><br />          <span style="color:#ffffff;">SelectionChanged</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;businessesListBox_SelectionChanged&quot; </span><br />          <span style="color:#ffffff;">Style</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">StaticResource BusinessListBoxStyle}</span><span style="color:#ffffff;">&quot;</span><span style="color:#0080c0;"> /&gt;</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>From Blend, I right-clicked my ListBox, chose “Edit Template” –&gt; “Edit a copy” to add that BusinessListBoxStyle, and added a handler for the ScrollViewer’s Loaded event.</p>
<p>&#160;</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c8dd9993-6f45-493c-a6a2-06272fc77fec" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">My ListBox&#8217; Style</div>
<div style="background-color:#001122;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Style x</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">Key</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;BusinessListBoxStyle&quot; TargetType</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;ListBox&quot;</span><span style="color:#0080c0;">&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Background&quot; Value</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Transparent&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Foreground&quot; Value</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">StaticResource PhoneForegroundBrush}</span><span style="color:#ffffff;">&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;ScrollViewer.HorizontalScrollBarVisibility&quot; Value</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Disabled&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;ScrollViewer.VerticalScrollBarVisibility&quot; Value</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Auto&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;BorderThickness&quot; Value</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;0&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;BorderBrush&quot; Value</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Transparent&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Padding&quot; Value</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;0&quot;</span><span style="color:#0080c0;">/&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter Property</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;Template&quot;</span><span style="color:#0080c0;">&gt;</span><br />         <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">Setter.Value</span><span style="color:#0080c0;">&gt;</span><br />             <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">ControlTemplate TargetType</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;ListBox&quot;</span><span style="color:#0080c0;">&gt;</span><br />                 <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">ScrollViewer x</span><span style="color:#0080c0;">:</span><span style="color:#ffffff;">Name</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;scrollViewer&quot; </span><br />                               <span style="color:#ffffff;">BorderBrush</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">TemplateBinding BorderBrush}</span><span style="color:#ffffff;">&quot; </span><br />                               <span style="color:#ffffff;">BorderThickness</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">TemplateBinding BorderThickness}</span><span style="color:#ffffff;">&quot; </span><br />                               <span style="color:#ffffff;">Background</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">TemplateBinding Background}</span><span style="color:#ffffff;">&quot; </span><br />                               <span style="color:#ffffff;">Foreground</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">TemplateBinding Foreground}</span><span style="color:#ffffff;">&quot; </span><br />                               <span style="color:#ffffff;">Padding</span><span style="color:#0080c0;">=&quot;{</span><span style="color:#ffffff;">TemplateBinding Padding}</span><span style="color:#ffffff;">&quot; </span><br />                               <span style="color:#ffffff;">Loaded</span><span style="color:#0080c0;">=</span><span style="color:#ffffff;">&quot;ScrollViewer_Loaded&quot;</span><span style="color:#0080c0;">&gt;</span><br />                     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;</span><span style="color:#ffffff;">ItemsPresenter</span><span style="color:#0080c0;">/&gt;</span><br />                 <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;/</span><span style="color:#ffffff;">ScrollViewer</span><span style="color:#0080c0;">&gt;</span><br />             <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;/</span><span style="color:#ffffff;">ControlTemplate</span><span style="color:#0080c0;">&gt;</span><br />         <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;/</span><span style="color:#ffffff;">Setter.Value</span><span style="color:#0080c0;">&gt;</span><br />     <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;/</span><span style="color:#ffffff;">Setter</span><span style="color:#0080c0;">&gt;</span><br /> <span style="color:#ffffff;"></span><span style="color:#0080c0;">&lt;/</span><span style="color:#ffffff;">Style</span><span style="color:#0080c0;">&gt;</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>I created a custom property in my PhoneApplicationPage.</p>
<p>&#160;</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4a27b4f1-bf88-4ec6-96aa-c7e5305352c8" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">My custom property</div>
<div style="background-color:#001122;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ffffff;"></span><span style="color:#ffffa0;">public</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">static</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">readonly</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">DependencyProperty</span><span style="color:#ffffff;"> ListVerticalOffsetProperty = </span><span style="color:#c0e0ff;">DependencyProperty</span><span style="color:#ffffff;">.Register(</span><br />   <span style="color:#ffffff;"></span><span style="color:#bff9d2;">&quot;ListVerticalOffset&quot;</span><span style="color:#ffffff;">,</span><br />   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">typeof</span><span style="color:#ffffff;">( </span><span style="color:#ffffa0;">double</span><span style="color:#ffffff;"> ),</span><br />   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">typeof</span><span style="color:#ffffff;">( </span><span style="color:#c0e0ff;">SearchBusinessResultsPage</span><span style="color:#ffffff;"> ),</span><br />   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">new</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">PropertyMetadata</span><span style="color:#ffffff;">( </span><span style="color:#ffffa0;">new</span><span style="color:#ffffff;"> </span><span style="color:#2b91af;">PropertyChangedCallback</span><span style="color:#ffffff;">( OnListVerticalOffsetChanged ) ) );</span></p>
<p> <span style="color:#ffffff;"></span><span style="color:#ffffa0;">public</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">double</span><span style="color:#ffffff;"> ListVerticalOffset</span><br /> <span style="color:#ffffff;">{</span><br />   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">get</span><span style="color:#ffffff;"> { </span><span style="color:#ffffa0;">return</span><span style="color:#ffffff;"> ( </span><span style="color:#ffffa0;">double</span><span style="color:#ffffff;"> )</span><span style="color:#ffffa0;">this</span><span style="color:#ffffff;">.GetValue( ListVerticalOffsetProperty ); }</span><br />   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">set</span><span style="color:#ffffff;"> { </span><span style="color:#ffffa0;">this</span><span style="color:#ffffff;">.SetValue( ListVerticalOffsetProperty, </span><span style="color:#ffffa0;">value</span><span style="color:#ffffff;"> ); }</span><br /> <span style="color:#ffffff;">}</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>From the ScrollViewer’s Loaded handler, I just need to bind my custom property to to the ScrollViewer’s VerticalOffset. Notice I keep a reference on the ScrollViewer, since it’s in a ContentTemplate.</p>
<p>&#160;</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5aea09ea-5fcd-4e20-8d24-ef2b0c6ea719" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">ScrollViewer&#8217;s Loaded handler</div>
<div style="background-color:#001122;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ffffff;"></span><span style="color:#ffffa0;">private</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">ScrollViewer</span><span style="color:#ffffff;"> _listScrollViewer;</span></p>
<p> <span style="color:#ffffff;"></span><span style="color:#ffffa0;">private</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">void</span><span style="color:#ffffff;"> ScrollViewer_Loaded( </span><span style="color:#ffffa0;">object</span><span style="color:#ffffff;"> sender, </span><span style="color:#c0e0ff;">RoutedEventArgs</span><span style="color:#ffffff;"> e )</span><br /> <span style="color:#ffffff;">{</span><br />   <span style="color:#ffffff;">_listScrollViewer = sender </span><span style="color:#ffffa0;">as</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">ScrollViewer</span><span style="color:#ffffff;">;</span></p>
<p>   <span style="color:#ffffff;"></span><span style="color:#c0e0ff;">Binding</span><span style="color:#ffffff;"> binding = </span><span style="color:#ffffa0;">new</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">Binding</span><span style="color:#ffffff;">();</span><br />   <span style="color:#ffffff;">binding.Source = _listScrollViewer;</span><br />   <span style="color:#ffffff;">binding.Path = </span><span style="color:#ffffa0;">new</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">PropertyPath</span><span style="color:#ffffff;">( </span><span style="color:#bff9d2;">&quot;VerticalOffset&quot;</span><span style="color:#ffffff;"> );</span><br />   <span style="color:#ffffff;">binding.Mode = </span><span style="color:#2b91af;">BindingMode</span><span style="color:#ffffff;">.OneWay;</span><br />   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">this</span><span style="color:#ffffff;">.SetBinding( ListVerticalOffsetProperty, binding );</span><br /> <span style="color:#ffffff;">}</span></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>The final job is to verify how far the scrolling is every time my custom property changes (thus every time the ScrollViewer’s VerticalOffset changes). I also make sure not to trigger updates more than once per ScrollableHeight.</p>
<p>&#160;</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5bff49f2-0dea-4530-a7c8-bc19790e80f1" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;">Scrolled to the bottom?</div>
<div style="background-color:#001122;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ffffff;"></span><span style="color:#ffffa0;">private</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">double</span><span style="color:#ffffff;"> _lastFetch;</span></p>
<p> <span style="color:#ffffff;"></span><span style="color:#ffffa0;">private</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">static</span><span style="color:#ffffff;"> </span><span style="color:#ffffa0;">void</span><span style="color:#ffffff;"> OnListVerticalOffsetChanged( </span><span style="color:#c0e0ff;">DependencyObject</span><span style="color:#ffffff;"> obj, </span><span style="color:#2b91af;">DependencyPropertyChangedEventArgs</span><span style="color:#ffffff;"> e )</span><br /> <span style="color:#ffffff;">{</span><br />   <span style="color:#ffffff;"></span><span style="color:#c0e0ff;">SearchBusinessResultsPage</span><span style="color:#ffffff;"> page = obj </span><span style="color:#ffffa0;">as</span><span style="color:#ffffff;"> </span><span style="color:#c0e0ff;">SearchBusinessResultsPage</span><span style="color:#ffffff;">;</span><br />   <span style="color:#ffffff;"></span><span style="color:#c0e0ff;">ScrollViewer</span><span style="color:#ffffff;"> viewer = page._listScrollViewer;</span></p>
<p>   <span style="color:#ffffff;"></span><span style="color:#ffffa0;">if</span><span style="color:#ffffff;">( viewer != </span><span style="color:#ffffa0;">null</span><span style="color:#ffffff;"> )</span><br />   <span style="color:#ffffff;">{</span><br />     <span style="color:#ffffff;"></span><span style="color:#ffffa0;">if</span><span style="color:#ffffff;">( page._lastFetch &lt; viewer.ScrollableHeight )</span><br />     <span style="color:#ffffff;">{</span><br />       <span style="color:#ffffff;"></span><span style="color:#ffb040;">// Trigger within 1/4 the viewport.</span><br />       <span style="color:#ffffff;"></span><span style="color:#ffffa0;">if</span><span style="color:#ffffff;">( viewer.VerticalOffset &gt;= viewer.ScrollableHeight &#8211; viewer.ViewportHeight / 4 )</span><br />       <span style="color:#ffffff;">{</span><br />         <span style="color:#ffffff;">page._lastFetch = viewer.ScrollableHeight;</span><br />         <span style="color:#ffffff;"></span><span style="color:#ffffa0;">this</span><span style="color:#ffffff;">.ViewModel.FetchNextPage();</span><br />       <span style="color:#ffffff;">}</span><br />     <span style="color:#ffffff;">}</span><br />   <span style="color:#ffffff;">}</span><br /> <span style="color:#ffffff;">}</span></div>
</p></div>
</p></div>
</p>
<p>&#160;</p>
<p>As you can see, you can adjust how close to the end you trigger an update. There is one final gotcha you much be warned of. Make sure your “FetchNextPage” equivalent prevents reentrancy, just in case adding a new item to your bound collection causes the OnListVerticalOffset event to fire (we never know) and another fetch is triggered.</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.slimcode.com/2010/09/11/detect-when-a-listbox-scrolls-to-its-end-wp7/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/45020afc2c207a7de30a5a92c9592806?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">slimcode</media:title>
		</media:content>
	</item>
	</channel>
</rss>
