<?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>Everything Silverlight &#187; images</title>
	<atom:link href="http://www.michaelsnow.com/tag/images/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michaelsnow.com</link>
	<description></description>
	<lastBuildDate>Thu, 28 Apr 2011 21:43:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Silverlight Tip of the Day #18 &#8211; Elastic Scrolling</title>
		<link>http://www.michaelsnow.com/2010/05/11/silverlight-tip-of-the-day-18-elastic-scrolling/</link>
		<comments>http://www.michaelsnow.com/2010/05/11/silverlight-tip-of-the-day-18-elastic-scrolling/#comments</comments>
		<pubDate>Tue, 11 May 2010 17:31:47 +0000</pubDate>
		<dc:creator>Snowman</dc:creator>
				<category><![CDATA[images]]></category>
		<category><![CDATA[scrolling]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[GalacticImg]]></category>

		<guid isPermaLink="false">http://www.silverlightdev.net/2010/05/11/silverlight-tip-of-the-day-18-elastic-scrolling/</guid>
		<description><![CDATA[If you have ever used an iPhone you will notice the scrolling is very elastic in nature. If you hit the end of the scroll it will go a little further before bouncing back. Also, the faster you flick your finger, the faster the scrolling starts off before gradually slowing down as the scrolling comes [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever used an iPhone you will notice the scrolling is very elastic in nature. If you hit the end of the scroll it will go a little further before bouncing back. Also, the faster you flick your finger, the faster the scrolling starts off before gradually slowing down as the scrolling comes to a stop.</p>
<p>I have updated my Image Viewer application (<a href="http://www.galacticimg.com">http://www.galacticimg.com</a>) to mimic this behavior. Since it’s not yet touch screen based, you can simply use mouse left click-hold to scroll rather than your finger.</p>
<p>The implementation is pretty straight forward but I am very interested in getting people’s feedback especially if you can think of a more efficient way to accomplish this.</p>
<p>To start, the following event is the event used to monitor for left mouse clicks. Velocity is used to determine the current scroll speed. VerticalOffset is the distance the panel has scrolled so far. The offsets are used to determine the speed of the scroll. As long as the mouse left button is down DraggingPanel will be set to true.</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">private</span> <span class="kwrd">double</span> _verticalOffset = 0.0; </pre>
<pre><span class="kwrd">private</span> <span class="kwrd">double</span> _offset = 0.0; </pre>
<pre class="alt"><span class="kwrd">private</span> <span class="kwrd">double</span> _previousOffset = 0.0; </pre>
<pre><span class="kwrd">private</span> <span class="kwrd">int</span> _velocity = 0; </pre>
<pre class="alt">&#160;</pre>
<pre><span class="kwrd">private</span> <span class="kwrd">void</span> PanelCanvas_MouseLeftButtonDown(<span class="kwrd">object</span> sender, MouseButtonEventArgs e) </pre>
<pre class="alt">{ </pre>
<pre>    <span class="kwrd">this</span>.Focus(); </pre>
<pre class="alt">    _draggingPanel = <span class="kwrd">true</span>; </pre>
<pre>    PanelCanvas.CaptureMouse(); </pre>
<pre class="alt">    _velocity = 0; </pre>
<pre>    _offset = e.GetPosition(<span class="kwrd">this</span>).X - _verticalOffset; </pre>
<pre class="alt">    _previousOffset = e.GetPosition(<span class="kwrd">this</span>).X; </pre>
<pre>} </pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>In the MouseMove event I check to see if the DraggingPanel is true (meaning the left mouse is still down). If so, I calculate the new position of the panel and determine the velocity based upon how fast the mouse is moving. Finally, I set the new position of the ThumbnailCanvas which is the Canvas that contains all my images.</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">private</span> <span class="kwrd">void</span> PanelCanvas_MouseMove(<span class="kwrd">object</span> sender, MouseEventArgs e) </pre>
<pre>{ </pre>
<pre class="alt">    <span class="kwrd">if</span> (<span class="kwrd">true</span> == _draggingPanel) </pre>
<pre>    { </pre>
<pre class="alt">        _verticalOffset = e.GetPosition(<span class="kwrd">this</span>).X - _offset; </pre>
<pre>        _velocity = (<span class="kwrd">int</span>)(e.GetPosition(<span class="kwrd">this</span>).X - _previousOffset); </pre>
<pre class="alt">        _previousOffset = e.GetPosition(<span class="kwrd">this</span>).X; </pre>
<pre>        ThumbnailCanvas.SetValue(Canvas.LeftProperty, (<span class="kwrd">double</span>)_verticalOffset); </pre>
<pre class="alt">    } </pre>
<pre>} </pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>
  </p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>If the mouse left click up event is fired I set DraggingPanel to false and release the mouse capture.</p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">private</span> <span class="kwrd">void</span> PanelCanvas_MouseLeftButtonUp(<span class="kwrd">object</span> sender, MouseButtonEventArgs e) </pre>
<pre>{ </pre>
<pre class="alt">    PanelCanvas.ReleaseMouseCapture(); </pre>
<pre>    _draggingPanel = <span class="kwrd">false</span>; </pre>
<pre class="alt">} </pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>I have a timer called EllasticScroll() that runs in the background. There are two conditions it checks for:</p>
<p>1. In the case where you scroll beyond the boundary of the images ScrollDistance is set and the panel “bounces back” to position zero.&#160; To test this out scroll to the left when you first start the <a href="http://www.galacticimg.com/#/Pages/PicturesPage">Galactic Image</a> app and you will see the bounce back effect.</p>
<p>2. The left mouse has been released and the auto-scrolling kicks in. It scrolls the panel based upon the current velocity which is trickled down to zero. If the scroll goes 200 pixels beyond the boundary, I stop the velocity setting it to zero and I set ScrollDistance so that is bounces back to zero.</p>
<div class="csharpcode">
<pre class="alt">_timer.Interval = TimeSpan.FromMilliseconds(20); </pre>
<pre>_timer.Tick += <span class="kwrd">new</span> EventHandler(EllasticScroll); </pre>
<pre class="alt">_timer.Start(); </pre>
<pre>&#160;</pre>
<pre class="alt"><span class="kwrd">private</span> <span class="kwrd">void</span> EllasticScroll(<span class="kwrd">object</span> sender, EventArgs e) </pre>
<pre>{ </pre>
<pre class="alt">    <span class="kwrd">if</span> (_scrollDistance != 0) </pre>
<pre>    { </pre>
<pre class="alt">        <span class="kwrd">int</span> distance = _scrollDistance / 10; </pre>
<pre>        _scrollCounter++; </pre>
<pre class="alt">        <span class="kwrd">if</span> (_scrollCounter == 10) </pre>
<pre>            _scrollDistance = 0; </pre>
<pre class="alt">        _verticalOffset += distance; </pre>
<pre>        <span class="kwrd">if</span> (_verticalOffset &gt; 0 &amp;&amp; distance &gt; 0) </pre>
<pre class="alt">            _verticalOffset = 0.0; </pre>
<pre>        ThumbnailCanvas.SetValue(Canvas.LeftProperty, (<span class="kwrd">double</span>)_verticalOffset); </pre>
<pre class="alt">    } </pre>
<pre>    <span class="kwrd">else</span> <span class="kwrd">if</span> (<span class="kwrd">false</span> == _draggingPanel &amp;&amp; _velocity != 0) </pre>
<pre class="alt">    { </pre>
<pre>        _verticalOffset += _velocity; </pre>
<pre class="alt">        ThumbnailCanvas.SetValue(Canvas.LeftProperty, (<span class="kwrd">double</span>)_verticalOffset); </pre>
<pre>        <span class="kwrd">double</span> v = (<span class="kwrd">double</span>)_velocity; </pre>
<pre class="alt">        v = v / 1.1; </pre>
<pre>        _velocity = (<span class="kwrd">int</span>)v; </pre>
<pre class="alt">        <span class="kwrd">if</span> (_verticalOffset &gt; 200) </pre>
<pre>        { </pre>
<pre class="alt">            _scrollCounter = 0; </pre>
<pre>            _velocity = 0; </pre>
<pre class="alt">            _scrollDistance = -(<span class="kwrd">int</span>)(_verticalOffset); </pre>
<pre>        } </pre>
<pre class="alt">    } </pre>
<pre>} </pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>If you need more details let me know. In the meantime, go over and check out the <a href="http://www.galacticimg.com/#/Pages/PicturesPage">application</a> and let me know what you think! </p>
<p>Thank you,<br />
  <br />&#8211;Mike</p>
<p><a href="http://www.galacticimg.com/#/Pages/PicturesPage"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.michaelsnow.com/wp-content/uploads/2010/06/image5.png" width="600" height="581" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.michaelsnow.com/2010/05/11/silverlight-tip-of-the-day-18-elastic-scrolling/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Silverlight Tip of the Day #12 &#8211; Getting an Images Source File Name</title>
		<link>http://www.michaelsnow.com/2010/05/04/silverlight-tip-of-the-day-12-getting-an-images-source-file-name/</link>
		<comments>http://www.michaelsnow.com/2010/05/04/silverlight-tip-of-the-day-12-getting-an-images-source-file-name/#comments</comments>
		<pubDate>Tue, 04 May 2010 17:02:24 +0000</pubDate>
		<dc:creator>Snowman</dc:creator>
				<category><![CDATA[images]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.silverlightdev.net/2010/05/04/silverlight-tip-of-the-day-12-getting-an-images-source-file-name/</guid>
		<description><![CDATA[Once you have an image loaded how do you go back and get the original file name for the source file? This can be accomplished through the Uri property of the images Source. However, you must first typecast the images Source to be a BitmapImage. The Uri has a property called OriginalString that returns the [...]]]></description>
			<content:encoded><![CDATA[<p>Once you have an image loaded how do you go back and get the original file name for the source file? </p>
<p>This can be accomplished through the Uri property of the images Source. However, you must first typecast the images Source to be a <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage(VS.95).aspx">BitmapImage</a>. The Uri has a property called <a href="http://msdn.microsoft.com/en-us/library/system.uri.originalstring.aspx">OriginalString</a> that returns the full relative path to the image file.</p>
<p>Example: </p>
<div class="csharpcode">
<pre class="alt"><span class="kwrd">public</span> <span class="kwrd">string</span> GetImageSourceFile(Image img) </pre>
<pre>{ </pre>
<pre class="alt">     BitmapImage bi = (BitmapImage)img.Source; </pre>
<pre>     Uri uri = bi.UriSource; </pre>
<pre class="alt">     <span class="kwrd">return</span> uri.OriginalString; </pre>
<pre>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage(VS.95).aspx">BitmapImage</a> can be found in the System.Windows.Media.Imaging namespace. </p>
<p>Thank you, </p>
<p>&#8211;Mike</p>
<pre>&#160;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.michaelsnow.com/2010/05/04/silverlight-tip-of-the-day-12-getting-an-images-source-file-name/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

