<?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>Sergiy Baydachnyy</title>
	<atom:link href="http://en.baydachnyy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://en.baydachnyy.com</link>
	<description>Blog about technologies</description>
	<lastBuildDate>Tue, 02 Feb 2010 05:58:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='en.baydachnyy.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Sergiy Baydachnyy</title>
		<link>http://en.baydachnyy.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://en.baydachnyy.com/osd.xml" title="Sergiy Baydachnyy" />
	<atom:link rel='hub' href='http://en.baydachnyy.com/?pushpress=hub'/>
		<item>
		<title>SilverLight 4: Drag &amp; Drop</title>
		<link>http://en.baydachnyy.com/2010/02/02/silverlight-4-drag-drop/</link>
		<comments>http://en.baydachnyy.com/2010/02/02/silverlight-4-drag-drop/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 05:56:17 +0000</pubDate>
		<dc:creator>Sergiy Baydachnyy</dc:creator>
				<category><![CDATA[SilverLight]]></category>
		<category><![CDATA[SilverLight 4]]></category>

		<guid isPermaLink="false">http://baydachnyyen.wordpress.com/2010/02/02/silverlight-4-drag-drop/</guid>
		<description><![CDATA[Several weeks ago SilverLight 4 was announced at PDC 09 but I am planning to publish some posts about this technology just now. I promise that I will be faster next time. We will start overview of new features called Drag &#38; Drop – a simple but a very nice feature. We will not tell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=en.baydachnyy.com&amp;blog=11565010&amp;post=11&amp;subd=baydachnyyen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Several weeks ago SilverLight 4 was announced at PDC 09 but I am planning to publish some posts about this technology just now. I promise that I will be faster next time.</p>
<p>We will start overview of new features called Drag &amp; Drop – a simple but a very nice feature. We will not tell about moving elements inside SilverLight application. We’ll just discuss transferring an external object (located on user computer) to SilverLight application.</p>
<p>Let’s create a new application in order to demonstrate this feature. We will try move user’s images (in supported format)&#160; to SilverLight application and then we will display them. For this reason SilverLight 4 supports a new property called <b>AllowDrop</b>. The property is implemented in UIElement class, so all of the visual elements have it. According to this, we can move external object to any visual element as well as container. If you set up the AllowDrop property to true, you will initiate four events which can be used for implementing the Drag &amp; Drop functionality: <b>Drop</b>, <b>DragEnter</b>, <b>DragLeave</b>, <b>DragOver</b>. </p>
<p>The main event is Drop. It is generated when the Drag&amp;Drop process is finished. Other three events are generated when the mouse pointer (which is dragging the object) moves but before the dropping actually happened. So these events are sort of subsidiary and can be used for additional visualization of the Drag&amp;Drop process in the interface. For example, certain areas where the object can be dropped can be marked with a different color.</p>
<p>Let’s implement a simple interface that contains a button and a panel like Canvas. An object based on Canvas can be used for our purposes best of all for it allows to stick the displayed image to the mouse pointer coordinates.</p>
<p>&lt;UserControl x:Class=&quot;DragAndDrop_Chapter0.MainPage&quot;</p>
<p>&#160;&#160;&#160; xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</p>
<p>&#160;&#160;&#160; xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&gt;</p>
<p>&#160;&#160;&#160; &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Grid.RowDefinitions&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;RowDefinition Height=&quot;50&quot;&gt;&lt;/RowDefinition&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;RowDefinition&gt;&lt;/RowDefinition&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Grid.RowDefinitions&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Button x:Name=&quot;printButton&quot; Content=&quot;Print&quot; Width=&quot;100&quot;&gt;&lt;/Button&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Border Grid.Row=&quot;1&quot; x:Name=&quot;photoBorder&quot; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BorderBrush=&quot;Blue&quot; BorderThickness=&quot;4&quot;&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;Canvas x:Name=&quot;photoPanel&quot; Grid.Row=&quot;1&quot; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Background=&quot;Gray&quot; AllowDrop=&quot;True&quot;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Drop=&quot;photoPanel_Drop&quot;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DragEnter=&quot;photoPanel_DragEnter&quot;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DragLeave=&quot;photoPanel_DragLeave&quot;&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Canvas&gt;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/Border&gt;</p>
<p>&#160;&#160;&#160; &lt;/Grid&gt;</p>
<p>&lt;/UserControl&gt;</p>
<p>We will use photoPanel for displaying images that had been dragged from the user’s computer. Here we have defined the AllowDrop property and set it to True. We also defined the event handler here. </p>
<p>Below you can find implementation of the Drop, DragEnter, DragLeave event handlers (these events are described above).</p>
<p>private void photoPanel_Drop(object sender, DragEventArgs e)</p>
<p>{</p>
<p>&#160;&#160;&#160; photoBorder.BorderBrush = new SolidColorBrush(Colors.Blue);</p>
<p>&#160;&#160;&#160; IDataObject data = e.Data;</p>
<p>&#160;&#160;&#160; FileInfo[] files = (FileInfo [])data.GetData</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; (DataFormats.FileDrop);</p>
<p>&#160;&#160;&#160; foreach (FileInfo f in files)</p>
<p>&#160;&#160;&#160; {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Stream s=f.OpenRead();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; BitmapImage bitmap=new BitmapImage();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; bitmap.SetSource(s);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Image img = new Image();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; img.Source = bitmap;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; img.Width = 100;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; img.Height = 80;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Point p = e.GetPosition(photoPanel);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; img.Margin = new Thickness(p.X, p.Y, 0, 0);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; photoPanel.Children.Add(img);</p>
<p>&#160;&#160;&#160; }</p>
<p>}</p>
<p>private void photoPanel_DragEnter(object sender, DragEventArgs e)</p>
<p>{</p>
<p>&#160;&#160;&#160; photoBorder.BorderBrush = new SolidColorBrush(Colors.Red);</p>
<p>}</p>
<p>private void photoPanel_DragLeave(object sender, DragEventArgs e)</p>
<p>{</p>
<p>&#160;&#160;&#160; photoBorder.BorderBrush = new SolidColorBrush(Colors.Blue);</p>
<p>}</p>
<p>Last two events are handled only to select the area that is available for dropping (please don’t forget that when the Drop event is generated the DragLeave event is not generated anymore. So selection in Drop must be taken off, too). The Drop event handler does all the main work. It receives information about the files transferred, opens the stream, loads and displays the image with the help of Pixel API ( one of the new things in Silverlight 3). To make the code easier to read we do not handle the errors that are connected with the file types. But in a real task it is a must (try to drag and drop a text file or an office document in this example).</p>
<br />Filed under: <a href='http://en.baydachnyy.com/category/silverlight/'>SilverLight</a> Tagged: <a href='http://en.baydachnyy.com/tag/silverlight-4/'>SilverLight 4</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baydachnyyen.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baydachnyyen.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baydachnyyen.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baydachnyyen.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baydachnyyen.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baydachnyyen.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baydachnyyen.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baydachnyyen.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=en.baydachnyy.com&amp;blog=11565010&amp;post=11&amp;subd=baydachnyyen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://en.baydachnyy.com/2010/02/02/silverlight-4-drag-drop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4de684fe59e1b6821afc4af4df983f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbaidachni</media:title>
		</media:content>
	</item>
		<item>
		<title>English version</title>
		<link>http://en.baydachnyy.com/2010/01/21/english-version/</link>
		<comments>http://en.baydachnyy.com/2010/01/21/english-version/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 07:44:23 +0000</pubDate>
		<dc:creator>Sergiy Baydachnyy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://baydachnyyen.wordpress.com/?p=9</guid>
		<description><![CDATA[I will translate my articles from http://baydachnyy.wordpress.com as soon as possible. Posted in Uncategorized<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=en.baydachnyy.com&amp;blog=11565010&amp;post=9&amp;subd=baydachnyyen&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I will translate my articles from <a href="http://baydachnyy.wordpress.com">http://baydachnyy.wordpress.com</a> as soon as possible.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/baydachnyyen.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/baydachnyyen.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/baydachnyyen.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/baydachnyyen.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/baydachnyyen.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/baydachnyyen.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/baydachnyyen.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/baydachnyyen.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=en.baydachnyy.com&amp;blog=11565010&amp;post=9&amp;subd=baydachnyyen&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://en.baydachnyy.com/2010/01/21/english-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4de684fe59e1b6821afc4af4df983f8d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sbaidachni</media:title>
		</media:content>
	</item>
	</channel>
</rss>
