<?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>Silverlight &#124; WPF &#124; Microsoft.Net</title>
	<atom:link href="http://joel.neubeck.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://joel.neubeck.net</link>
	<description>Simplifing structure without changing results</description>
	<lastBuildDate>Fri, 01 Apr 2011 21:34:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Nomadic is Hiring &#8211; Experienced .NET Developer</title>
		<link>http://joel.neubeck.net/2010/05/nomadic-net-developer/</link>
		<comments>http://joel.neubeck.net/2010/05/nomadic-net-developer/#comments</comments>
		<pubDate>Wed, 26 May 2010 18:31:30 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Nomadic]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Job]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=465</guid>
		<description><![CDATA[As many of you know I recently joined Nomadic, a a full service branding and interactive digital agency in North Scottsdale.  If you haven&#8217;t heard of Nomadic, check out our site http://www.nomadicagency.com.  We get to work with some amazing brands and develop some really exciting sites as well as online promotions. To keep up with [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.nomadicagency.com"><img class="alignleft size-full wp-image-466" title="Nomadic" src="http://joel.neubeck.net/wp-content/uploads/2010/05/n57200823107_7173.jpg" alt="" width="200" height="127" /></a>As many of you know I recently joined Nomadic, a a full service branding and interactive  digital agency in North Scottsdale.  If you haven&#8217;t heard of Nomadic, check out our site http://www.nomadicagency.com.  We get to work with some amazing brands and develop some really exciting sites as well as online promotions.</p>
<p>To keep up with the exciting work we have coming in, we are in need of a seasoned .NET developer.  Here is a quick description of the job.</p>
<p><strong>Senior .NET Developer</strong></p>
<p><strong>Key Responsibilities:</strong></p>
<ul>
<li>Serve as the lead programmer on multiple projects.</li>
<li>Ability to estimate project tasks, ensuring delivery of projects on-time and to  specification</li>
<li>Being self-directed and architecturally innovative</li>
<li>Help analyze, design, code, test, debug and provide enhancements to existing software.</li>
<li>Work closely with a team as well as interfacing with various external Client and Business Groups.</li>
</ul>
<p><strong>Qualifications</strong></p>
<ul>
<li>Bachelors Degree, MCSD certification or other advanced level of industry certification.</li>
<li>Minimum five(5) years working experience with Microsoft .Net (ASP.NET, C# and/or VB.NET).
<ul>
<li>Experience using various separation patterns such as: MVC, MVVM and MVP</li>
</ul>
</li>
<li>Minimum two (2) years experience with WCF (Windows Communication Foundation) experience</li>
<li>Minimum five(5) years working experience with SQL Server or other advanced level databases
<ul>
<li>Strong database modeling skills</li>
<li>Experience  with Object-relational mapping (ORM) using Entity Framework, Linq-To-Sql or  <em>NHibernate</em>.</li>
</ul>
</li>
<li>Excellent oral and written professional communication skills that project a positive, professional image.</li>
</ul>
<p>If you are interested in this opportunity please apply by sending a resume to careers@nomadicagency.com.</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2010/05/nomadic-net-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight Connections &#8211; November 1-4, 2010</title>
		<link>http://joel.neubeck.net/2010/05/sl-connections-2010/</link>
		<comments>http://joel.neubeck.net/2010/05/sl-connections-2010/#comments</comments>
		<pubDate>Fri, 21 May 2010 15:59:59 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Dev Connections]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[Speaking]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=461</guid>
		<description><![CDATA[I am very excited to announce that this year I will be presenting three unique sessions at Silverlight Connections in Las Vegas, Nevada  Nov 1-4, 2010.  I have never got the pleasure of attending this conference and look forward to being a part of three days of in-depth sessions on Silverlight and WP7. DESIGN LDS203: [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.devconnections.com/shows/FALL2010ASP/default.asp?s=151"><img class="alignleft size-full wp-image-462" title="Dev Connections" src="http://joel.neubeck.net/wp-content/uploads/2010/05/F10_ASP_Wahlin.jpg" alt="Dev Connections - Nov 1-4" width="220" height="225" /></a><br />
I am very excited to announce that this year I will be presenting three unique sessions at <strong>Silverlight Connections in Las Vegas, Nevada  Nov 1-4, 2010</strong>.   I have never got the pleasure of attending this conference and look forward to being a part of three days of in-depth sessions on Silverlight and WP7.<br style="clear: both;" /><br />
<strong>DESIGN</strong><br />
<a href="http://www.devconnections.com/shows/FALL2010ASP/default.asp?c=1&amp;s=151">LDS203: Expression Blend Is Not Only for Designers</a><br />
As a developer if you think that Expression Blend is only for designers, you&#8217;re missing out on an incredible opportunity. Interactive developers should embrace Expression blend as a powerful development tool that enhances Visual Studio. Come learn various tips and tricks that will help developers know when to use Blend and when to use Visual Studio. Finding the balance will speed up the development work flow and make you a more powerful developer.</p>
<p><strong>WINDOWS PHONE 7</strong><br />
<a href="http://www.devconnections.com/shows/FALL2010ASP/default.asp?c=1&amp;s=151">LWP202: Interaction Design for Windows Phone 7</a><br />
When building a WP7 application, the nature of the small multi-touch  screen requires good interaction design. Our choices around how our  users interact with our application will define its success. Learn how  to incorporate innovative work flows which build upon the power of the  mobile device. In this session, we will look at how the effective use of  multi-touch gestures, panoramic layouts and the effective use of  transitions can take your app to the next level.</p>
<p><strong>ANIMATIONS</strong><br />
<a href="http://www.devconnections.com/shows/FALL2010ASP/default.asp?c=1&amp;s=151">LAN201: Using Silverlight Animations to Improve User Experience in LOB Applications</a><br />
In this session, we will look at the use of animations and natural movement to enhance a user&#8217;s interaction with Silverlight LOB applications. Find out how simple effects, natural easing and fluid transitions can improve how your users navigate throughout your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2010/05/sl-connections-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Developer Tools April 2010 Refresh</title>
		<link>http://joel.neubeck.net/2010/04/windows-phone-7-developer-tools-april-2010-refresh/</link>
		<comments>http://joel.neubeck.net/2010/04/windows-phone-7-developer-tools-april-2010-refresh/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 17:36:23 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[Wp7]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=457</guid>
		<description><![CDATA[Today Microsoft released the latest version of the Windows Phone 7 Developer tools.   This version is free to the community and will will work correctly with Visual Studio 2010 final release. Click here to download the tools.]]></description>
			<content:encoded><![CDATA[<p><a href="http://joel.neubeck.net/wp-content/uploads/2010/04/wp7_handset.jpg"><img class="alignleft size-medium wp-image-458" title="wp7_handset" src="http://joel.neubeck.net/wp-content/uploads/2010/04/wp7_handset-155x300.jpg" alt="" height="150" /></a>Today Microsoft released the latest version of the Windows Phone 7 Developer tools.   This version is free to the community and will will work correctly with Visual Studio 2010 final release.  <a href="http://timh.me/wp7-apr2010">Click here</a> to download the tools.</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2010/04/windows-phone-7-developer-tools-april-2010-refresh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Silverlight 4 How to Command Control</title>
		<link>http://joel.neubeck.net/2010/02/silverlight-4-how-to-command-control/</link>
		<comments>http://joel.neubeck.net/2010/02/silverlight-4-how-to-command-control/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 18:20:38 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Binding]]></category>
		<category><![CDATA[Commanding]]></category>
		<category><![CDATA[Silverlight 4]]></category>
		<category><![CDATA[Silverlightshow]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=437</guid>
		<description><![CDATA[Checkout my latest article on the use of commanding in Silverlight 4. In this article I demonstrate how through the use of commanding and intelligent binding we can virtually eliminate all code behind and implement to a strong MVVM architectural pattern.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.silverlightshow.net/items/Silverlight-4-How-to-Command-Control.aspx"><img title="Silverlightshow" src="http://joel.neubeck.net/wp-content/uploads/2009/12/Silverlight.jpg" alt="Silverlight" width="341" height="95" /></a>Checkout my latest article on the use of commanding in Silverlight 4. In this article I demonstrate how through the use of commanding and intelligent binding we can virtually eliminate all code behind and implement to a strong MVVM architectural pattern.</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2010/02/silverlight-4-how-to-command-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight 4 Webcam Article</title>
		<link>http://joel.neubeck.net/2009/12/silverlight-4-webcam-article/</link>
		<comments>http://joel.neubeck.net/2009/12/silverlight-4-webcam-article/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 19:08:39 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[CaptureSource]]></category>
		<category><![CDATA[Isolated Storage]]></category>
		<category><![CDATA[PixelShader]]></category>
		<category><![CDATA[Silverlight 4]]></category>
		<category><![CDATA[VideoCaptureDevice]]></category>
		<category><![CDATA[Webcam]]></category>
		<category><![CDATA[WriteableBitmap]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=434</guid>
		<description><![CDATA[Checkout my latest article on the use of  the Webcam in Silverlight 4. The article demonstrates how to attach to a device apply a PixelShader then store a captured JPEG in Isolated Storage .]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.silverlightshow.net/items/Capturing-the-Webcam-in-Silverlight-4.aspx"><img class="aligncenter size-full wp-image-435" title="Silverlightshow" src="http://joel.neubeck.net/wp-content/uploads/2009/12/Silverlight.jpg" alt="Silverlight" width="341" height="95" /></a>Checkout my latest article on the use of  the Webcam in Silverlight 4. The article demonstrates how to attach to a device apply a PixelShader then store a captured JPEG in Isolated Storage .</p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/12/silverlight-4-webcam-article/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Navigation Transitions with WriteableBitmap</title>
		<link>http://joel.neubeck.net/2009/08/navigation-transitions-with-writeablebitmap/</link>
		<comments>http://joel.neubeck.net/2009/08/navigation-transitions-with-writeablebitmap/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 17:16:03 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Easing]]></category>
		<category><![CDATA[HyperlinkButton]]></category>
		<category><![CDATA[Navigation]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[WriteableBitmap]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2009/08/navigation-transitions-with-writeablebitmap/</guid>
		<description><![CDATA[If you have not had a chance to play with Navigation Frames in Silverlight they are very cool, they give developers the ability to navigate between &#34;Page&#34; within a single Silverlight Solution.&#160; The first time I used them I could believe how easy it was to implement.&#160; You simply add a few pages to your [...]]]></description>
			<content:encoded><![CDATA[<p>If you have not had a chance to play with Navigation Frames in Silverlight they are very cool, they give developers the ability to navigate between &quot;Page&quot; within a single Silverlight Solution.&#160; The first time I used them I could believe how easy it was to implement.&#160; You simply add a few pages to your solution, drop a Navigation:Frame on to your MainPage.xaml UserControl and define some UriMappers.</p>
<p>One thing that i thought was missing was the ability to&#160; create nice looking transitions between pages as they are loaded into a frame.&#160; Recently I voiced my complaint to a coworker (the infamous Steve Saxon &#8211; <a href="http://twitter.com/xmlguy" target="_blank">@xmlguy</a>) and he had the great idea of using a WritableBitmap to capture the current and next page within the Frame, than animating the images.&#160; Here is the solution I arrived at.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
&nbsp;
namespace NavigationTransition
{
    public partial class MainPage : UserControl
    {
        private HyperlinkButton _lastClicked;
        private bool _isNavigating = false;
        private readonly Image _imgLast = new Image();
        private readonly Image _imgNext = new Image();
        private Storyboard _sb = new Storyboard();
&nbsp;
        public MainPage()
        {
            InitializeComponent();
        }
&nbsp;
        void SbCompleted(object sender, EventArgs e)
        {
            Panel panel = ContentFrame.Parent as Panel;
            panel.Children.Remove(_imgLast);
            panel.Children.Remove(_imgNext);
            ContentFrame.Visibility = Visibility.Visible;
            _sb.Stop();
            _isNavigating = false;
        }
&nbsp;
        private void ContentFrameNavigated(object sender, NavigationEventArgs e)
        {
            ContentFrame.Navigated -= ContentFrameNavigated;
            Panel panel = ContentFrame.Parent as Panel;
            panel.UpdateLayout();
&nbsp;
            WriteableBitmap bitmapN = new WriteableBitmap(ContentFrame, new TranslateTransform());
            _imgNext.Source = bitmapN;
            TranslateTransform ttNext = new TranslateTransform();
&nbsp;
            _imgNext.RenderTransform = ttNext;
            panel.Children.Add(_imgNext);
&nbsp;
            _sb.Children.Add(CreateDoubleAnimation(ttNext, &amp;quot;X&amp;quot;, -bitmapN.PixelWidth, 0, true)); 
            ContentFrame.Visibility = Visibility.Collapsed;
&nbsp;
            _sb.Begin();
&nbsp;
        }
&nbsp;
&nbsp;
        private void Nav_Click(object sender, RoutedEventArgs e)
        {
            _lastClicked = (HyperlinkButton)sender;
            if (ContentFrame.Source.ToString() != _lastClicked.Tag.ToString() &amp;amp;&amp;amp; !_isNavigating)
            {
                _sb = new Storyboard();
                _sb.Completed += SbCompleted;
&nbsp;
                Panel panel = ContentFrame.Parent as Panel;
&nbsp;
                WriteableBitmap bitmapL = new WriteableBitmap(ContentFrame, new TranslateTransform());
                _imgLast.Source = bitmapL;
                TranslateTransform ttLast = new TranslateTransform();
                _imgLast.RenderTransform = ttLast;
                if (panel != null) panel.Children.Add(_imgLast);
&nbsp;
                ContentFrame.Navigated += ContentFrameNavigated;
                ContentFrame.Navigate(new Uri(_lastClicked.Tag.ToString(), UriKind.Relative));
&nbsp;
                _sb.Children.Add(CreateDoubleAnimation(ttLast, &amp;quot;X&amp;quot;, 0, bitmapL.PixelWidth, true));
&nbsp;
                _isNavigating = true;
            }  
        }
        private static DoubleAnimation CreateDoubleAnimation(DependencyObject element, 
              string property, double from, double to, bool addEasing)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.To = to;
            da.From = from;
            if (addEasing)
                da.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseOut, Power = 3 };
&nbsp;
&nbsp;
            Storyboard.SetTargetProperty(da, new PropertyPath(property));
            Storyboard.SetTarget(da, element);
            return da;
        }
        // If an error occurs during navigation, show an error window
        private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
        {
            e.Handled = true;
            ChildWindow errorWin = new ErrorWindow(e.Uri);
            errorWin.Show();
        }
    }
}</pre></td></tr></table></div>

<p>One of the things I found necessary was to delay the navigation so that I could capture a bitmap of the current frame.&#160; The way I intersected the navigation&#160; was to attach a Click event handler to my HyperlinkButton and then store the Uri in the Tag property.&#160; With a little more effort you could make this into a Behavior or even add a few additional types of transitions.</p>
<p>&#160; <br style="clear: both" /><iframe height="300" src="/wp-content/uploads/2009/08/NavigationTransition/" width="500"></iframe></p>
<p>  <br style="clear: both" />Code: <a onclick="javascript:pageTracker._trackPageview(&#39;/code/NavigationTransition.zip&#39;); " href="/wp-content/uploads/2009/08/NavigationTransition/NavigationTransition.zip">NavigationTransition.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/08/navigation-transitions-with-writeablebitmap/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Control Visibility with triggers</title>
		<link>http://joel.neubeck.net/2009/08/control-visibility-with-triggers/</link>
		<comments>http://joel.neubeck.net/2009/08/control-visibility-with-triggers/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 21:30:10 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[CheckBox]]></category>
		<category><![CDATA[ComboBox]]></category>
		<category><![CDATA[ListBox]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[TargetedTriggerAction]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/2009/08/control-visibility-with-triggers/</guid>
		<description><![CDATA[I absolutely love writing triggers for Silverlight 3.&#160; As UX developers we often faced with the challenge of finding ways to fit a ton of information on a single user input screen.&#160; On occasion, some of that information may only be relevant to display if users have made certain choices on the interface: checking a [...]]]></description>
			<content:encoded><![CDATA[<p>I absolutely love writing triggers for Silverlight 3.&#160; As UX developers we often faced with the challenge of finding ways to fit a ton of information on a single user input screen.&#160; On occasion, some of that information may only be relevant to display if users have made certain choices on the interface: checking a box, selecting an item in a combobox or listbox.&#160; In this post I will include two custom TargetedTriggerAction’s which allow a developer to easily tie a UIElement’s visibility to an action made on another control.</p>
<h2>VisibilityIsChecked</h2>
<p>This first trigger I very simple.&#160; I wanted the ability to tie a checkbox to the visibility of another UIElement.&#160; Since a checkbox derives from ToggleButton we can get creative and write a single trigger that will work with either a CheckBox, RadioButton or ToggleButton.&#160; Here is how I did it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Interactivity;
&nbsp;
namespace VisibilityTriggers
{
    public class VisibilityIsChecked : TargetedTriggerAction&lt;frameworkelement&gt;
    {
        public static readonly DependencyProperty VisibleWhenCheckedProperty =
            DependencyProperty.Register(&amp;quot;VisibleWhenChecked&amp;quot;, typeof(bool), 
            typeof(VisibilityIsChecked), new PropertyMetadata(true));
        public bool VisibleWhenChecked
        {
            get
            {
                return (bool)GetValue(VisibleWhenCheckedProperty);
            }
            set
            {
                SetValue(VisibleWhenCheckedProperty, value);
            }
        }
&nbsp;
        protected override void OnAttached()
        {
            base.OnAttached();
            FrameworkElement element = this.AssociatedObject as FrameworkElement;
            if (element != null) element.Loaded += TargetLoaded;
        }
&nbsp;
        void TargetLoaded(object sender, RoutedEventArgs e)
        {
            ToggleButton tb = this.AssociatedObject as ToggleButton;
            SetVisibility(tb);
        }
        protected override void Invoke(object parameter)
        {
            RoutedEventArgs args = parameter as RoutedEventArgs;
&nbsp;
            if (args != null)
            {
                ToggleButton tb = args.OriginalSource as ToggleButton;
                SetVisibility(tb);
            }
        }
&nbsp;
        private void SetVisibility(ToggleButton tb)
        {
            if (tb != null)
            {
                Target.Visibility = ((bool)tb.IsChecked == VisibleWhenChecked) ? 
                Visibility.Visible : Visibility.Collapsed;
            }
        }
    }
}</pre></td></tr></table></div>

<p>To implement this trigger, we simply add an EventTrigger to a checkbox and set the TargetName to the control I want to visualize. Since there are times that we want IsChecked to either show or hide the element I have included a DependencyProperty called VisibileWhenChecked that can alter this behavior.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">&lt;checkbox content=&quot;Show?&quot; margin=&quot;5&quot;&gt;
    &lt;i:interaction.triggers&gt;
        &lt;i:eventtrigger eventname=&quot;Click&quot;&gt;
            &lt;triggers:visibilityischecked targetname=&quot;rectangle&quot; /&gt;
        &lt;/i:eventtrigger&gt;
    &lt;/i:interaction.triggers&gt;
&lt;/checkbox&gt;
&lt;rectangle margin=&quot;10&quot; x:name=&quot;rectangle&quot; width=&quot;100&quot; height=&quot;100&quot; fill=&quot;Yellow&quot; visibility=&quot;Collapsed&quot; /&gt;</pre></td></tr></table></div>

<h2>VisibilitySelectedItem</h2>
<p>The second TargetedTriggerAction I created achieves a similar result, but instead of targeting a checkbox or radio button, it targets a ComboBox or ListBox. In this trigger I will flip a UIElements visibility based on a specific value being returned from a selection in the the ListBox. Here is how I implemented the trigger.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">using System.Collections;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Interactivity;
&nbsp;
namespace VisibilityTriggers
{
    public class VisibilitySelectedItem : TargetedTriggerAction&lt;frameworkelement&gt;
    {
        public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register(&amp;quot;Value&amp;quot;, typeof(object), typeof(VisibilitySelectedItem), null);
&nbsp;
        public object Value
        {
            get
            {
                return (object)GetValue(ValueProperty);
            }
            set
            {
                SetValue(ValueProperty, value);
            }
        }
&nbsp;
        public static readonly DependencyProperty MatchMemberPathProperty =
            DependencyProperty.Register(&amp;quot;MatchMemberPath&amp;quot;, typeof(string), typeof(VisibilitySelectedItem), new PropertyMetadata(&amp;quot;Content&amp;quot;));
&nbsp;
        public string MatchMemberPath
        {
            get
            {
                return (string)GetValue(MatchMemberPathProperty);
            }
            set
            {
                SetValue(MatchMemberPathProperty, value);
            }
        }
&nbsp;
        protected override void OnAttached()
        {
            base.OnAttached();
            FrameworkElement element = this.AssociatedObject as FrameworkElement;
            if (element != null) element.Loaded += TargetLoaded;
        }
&nbsp;
        void TargetLoaded(object sender, RoutedEventArgs e)
        {
            FrameworkElement element = this.AssociatedObject as FrameworkElement;
            Selector cb = this.Target as Selector;
            if (cb != null)
            {
                int index = cb.SelectedIndex &amp;gt; -1 ? cb.SelectedIndex : 0;
                object item = (cb.Items.Count &amp;gt; 0) ? cb.Items[index] as object : null;
&nbsp;
                if (item != null)
                {
                    System.Reflection.PropertyInfo pi = item.GetType().GetProperty(MatchMemberPath);
                    var value = (pi != null) ? pi.GetValue(item, null) as object : item;
                    bool match = Equals(value, Value);
                    if (element != null) element.Visibility = match ? Visibility.Visible : Visibility.Collapsed;
                }
            }
        }
        protected override void Invoke(object parameter)
        {
            FrameworkElement element = this.AssociatedObject as FrameworkElement;
            SelectionChangedEventArgs args = parameter as SelectionChangedEventArgs;
&nbsp;
            if (args != null)
            {
                IList list = args.AddedItems as IList;
                if (list != null)
                {
                    foreach (object item in list)
                    {
                        System.Reflection.PropertyInfo pi = item.GetType().GetProperty(MatchMemberPath);
                        var value = (pi != null) ? pi.GetValue(item, null) as object : item;
&nbsp;
                        bool match = Equals(value, Value);
                        if (element != null) element.Visibility = match ? Visibility.Visible : Visibility.Collapsed;
                    }
                }
            }
        }
    }
}</pre></td></tr></table></div>

<p>To implement this TargetedTriggerAction you will place the custom EventTrigger on the item you want to visualize and target the SelectionChanged event on the ListBox (or ComboBox). Since we only want to visualize when a specific value is returned, we will also specifiy a &quot;Value&quot; and which property of our ListBox&#8217;s ItemSource we are targeting (MatchMemeberPath). The following is one way in which we can implement the trigger.&#160;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="c-sharp" style="font-family:monospace;">&lt;listbox x:name=&quot;myComboBox2&quot; width=&quot;100&quot; itemssource=&quot;{Binding Path=Items}&quot; displaymemberpath=&quot;Description&quot; /&gt;
&lt;rectangle margin=&quot;10&quot; width=&quot;100&quot; height=&quot;100&quot; fill=&quot;Silver&quot; visibility=&quot;Collapsed&quot;&gt;
    &lt;i:interaction.triggers&gt;
        &lt;i:eventtrigger eventname=&quot;SelectionChanged&quot; sourcename=&quot;myComboBox2&quot;&gt;
            &lt;triggers:visibilityselecteditem targetname=&quot;myComboBox2&quot; value=&quot;I1&quot; matchmemberpath=&quot;Code&quot; /&gt;
        &lt;/i:eventtrigger&gt;
    &lt;/i:interaction.triggers&gt;
&lt;/rectangle&gt;
&lt;ellipse margin=&quot;10&quot; width=&quot;100&quot; height=&quot;100&quot; fill=&quot;SaddleBrown&quot; visibility=&quot;Collapsed&quot;&gt;
    &lt;i:interaction.triggers&gt;
        &lt;i:eventtrigger eventname=&quot;SelectionChanged&quot; sourcename=&quot;myComboBox2&quot;&gt;
            &lt;triggers:visibilityselecteditem targetname=&quot;myComboBox2&quot; value=&quot;I2&quot; matchmemberpath=&quot;Code&quot; /&gt;
        &lt;/i:eventtrigger&gt;
    &lt;/i:interaction.triggers&gt;
&lt;/ellipse&gt;</pre></td></tr></table></div>

<p><br style="clear: both" /><iframe height="300" src="/wp-content/uploads/2009/08/VisibilityTriggers/" width="500"></iframe><br />
<br style="clear: both" /><br />
Code: <a onclick="javascript:pageTracker._trackPageview(&#39;/code/VisibilityTriggers.zip&#39;); " href="/wp-content/uploads/2009/08/VisibilityTriggers/VisibilityTriggers.zip">VisibilityTriggers.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/08/control-visibility-with-triggers/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Silverlight 3 Flip TargetedTriggerAction</title>
		<link>http://joel.neubeck.net/2009/08/silverlight-3-flip-targetedtriggeraction/</link>
		<comments>http://joel.neubeck.net/2009/08/silverlight-3-flip-targetedtriggeraction/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 22:36:41 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[3D Flip]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[TargetedTriggerAction]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=421</guid>
		<description><![CDATA[Last week I created a Trigger Action which flipped a panel. It was intended to be invoked from clicking on the panel directly. Earlier today I was asked if you could invoke this trigger from multiple places. The answer is no, but it is very easily to rewrite this trigger to achieve this behavior. In [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I created a Trigger Action which flipped a panel.  It was intended to be invoked from clicking on the panel directly.  Earlier today I was asked if you could invoke this trigger from multiple places.  The answer is no, but it is very easily to rewrite this trigger to achieve this behavior.  In this blog post I am going to create a TargetedTriggerAction which allows me to add the trigger to a button or multiple UIElement and &#8220;Target&#8221; a panel to be flipped.  What is really cool about this approach is that each button can contain the logic used to flip the panel (Storyboard direction, duration, etc).</p>
<p> The following is the code I used to create my Flip TargetedTriggerAction.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">using System.ComponentModel;
using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Media;
using System.Windows.Media.Animation;
&nbsp;
namespace FlipTargetedTrigger
{
    public enum RotationDirection
    {
        LeftToRight,
        RightToLeft,
        TopToBottom,
        BottomToTop
    }
&nbsp;
    public class Flip : TargetedTriggerAction&lt;FrameworkElement&gt;
    {
        public static readonly DependencyProperty FrontElementNameProperty =
            DependencyProperty.Register(&quot;FrontElementName&quot;, typeof(string),
                                        typeof(Flip), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Flip Properties&quot;)]
        public string FrontElementName
        {
            get
            {
                return (string)GetValue(FrontElementNameProperty);
            }
            set
            {
                SetValue(FrontElementNameProperty, value);
            }
        }
&nbsp;
        public static readonly DependencyProperty BackElementNameProperty =
            DependencyProperty.Register(&quot;BackElementName&quot;, typeof(string),
                                        typeof(Flip), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Flip Properties&quot;)]
        public string BackElementName
        {
            get
            {
                return (string)GetValue(BackElementNameProperty);
            }
            set
            {
                SetValue(BackElementNameProperty, value);
            }
        }
&nbsp;
        public static readonly DependencyProperty DurationProperty =
            DependencyProperty.Register(&quot;Duration&quot;, typeof(Duration),
                                        typeof(Flip), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Animation Properties&quot;)]
        public Duration Duration
        {
            get
            {
                return (Duration)GetValue(DurationProperty);
            }
            set
            {
                SetValue(DurationProperty, value);
            }
        }
&nbsp;
        public static readonly DependencyProperty RotationProperty =
            DependencyProperty.Register(&quot;Rotation&quot;, typeof(RotationDirection),
                                        typeof(Flip), new PropertyMetadata(RotationDirection.LeftToRight));
&nbsp;
        [Category(&quot;Animation Properties&quot;)]
        public RotationDirection Rotation
        {
            get
            {
                return (RotationDirection)GetValue(RotationProperty);
            }
            set
            {
                SetValue(RotationProperty, value);
            }
        }
&nbsp;
        public static readonly DependencyProperty FrontStoryboardProperty =
            DependencyProperty.Register(&quot;FrontStoryboard&quot;, typeof(Storyboard), typeof(Flip), null);
&nbsp;
        public Storyboard FrontStoryBoard
        {
            get
            {
                return (Storyboard)GetValue(FrontStoryboardProperty);
            }
        }
        public static readonly DependencyProperty BackStoryboardProperty =
            DependencyProperty.Register(&quot;BackStoryboard&quot;, typeof(Storyboard), typeof(Flip), null);
&nbsp;
        public Storyboard BackStoryboard
        {
            get
            {
                return (Storyboard)GetValue(BackStoryboardProperty);
            }
        }
&nbsp;
        private bool _forward = true;
&nbsp;
        protected override void OnAttached()
        {
            base.OnAttached();
            FrameworkElement element = this.AssociatedObject as FrameworkElement;
            if (element != null) element.Loaded += TargetLoaded;
        }
&nbsp;
        void TargetLoaded(object sender, RoutedEventArgs e)
        {
            PlaneProjection pp = Target.Projection as PlaneProjection;
            if (Target.Projection == null)
            {
                pp = new PlaneProjection { CenterOfRotationY = .51 };
&nbsp;
                Target.RenderTransformOrigin = new Point(.5, .5);
                Target.Projection = pp;
            }
&nbsp;
            Storyboard sbF = new Storyboard();
            Storyboard sbB = new Storyboard();
&nbsp;
            UIElement f = null;
            UIElement b = null;
&nbsp;
            f = Target.FindName(FrontElementName) as UIElement;
            if (f != null)
            {
                PlaneProjection ppFront = new PlaneProjection { CenterOfRotationY = .51 };
                f.Projection = ppFront;
                f.RenderTransformOrigin = new Point(.5, .5);
            }
            b = Target.FindName(BackElementName) as UIElement;
            if (b != null)
            {
                PlaneProjection ppBack = new PlaneProjection { CenterOfRotationY = .51, RotationY = 180.0 };
                b.Projection = ppBack;
                b.RenderTransformOrigin = new Point(.5, .5);
                b.Opacity = 0.0;
            }
&nbsp;
&nbsp;
            double to = 0.0;
            double from = 180.0;
            string property = &quot;RotationY&quot;;
&nbsp;
            switch (Rotation)
            {
                case RotationDirection.RightToLeft:
                    to = 180.0;
                    from = 0.0;
                    break;
                case RotationDirection.TopToBottom:
                    property = &quot;RotationX&quot;;
                    break;
                case RotationDirection.BottomToTop:
                    to = 0.0;
                    from = 180.0;
                    property = &quot;RotationX&quot;;
                    break;
            }
&nbsp;
            sbF.Duration = Duration;
            sbB.Duration = Duration;
&nbsp;
            sbF.Children.Add(CreateDoubleAnimation(pp, property, from, to, true));
            sbB.Children.Add(CreateDoubleAnimation(pp, property, to, from, true));
&nbsp;
            sbF.Children.Add(CreateDoubleAnimation(f, &quot;Opacity&quot;, 1.0, 0.0, false));
            sbB.Children.Add(CreateDoubleAnimation(f, &quot;Opacity&quot;, 0.0, 1.0, false));
&nbsp;
            sbF.Children.Add(CreateDoubleAnimation(b, &quot;Opacity&quot;, 0.0, 1.0, false));
            sbB.Children.Add(CreateDoubleAnimation(b, &quot;Opacity&quot;, 1.0, 0.0, false));
&nbsp;
            SetValue(FrontStoryboardProperty, sbF);
            SetValue(BackStoryboardProperty, sbB);
&nbsp;
&nbsp;
        }
&nbsp;
        protected override void Invoke(object parameter)
        {
            Storyboard sbF = GetValue(FrontStoryboardProperty) as Storyboard;
            Storyboard sbB = GetValue(BackStoryboardProperty) as Storyboard;
&nbsp;
            if (_forward)
            {
                sbF.Begin();
                _forward = false;
            }
            else
            {
                sbB.Begin();
                _forward = true;
            }
        }
&nbsp;
        private static DoubleAnimation CreateDoubleAnimation(DependencyObject element, string property, double from,
                                                             double to, bool addEasing)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.To = to;
            da.From = from;
            if (addEasing)
                da.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseOut, Power = 3 };
&nbsp;
            Storyboard.SetTargetProperty(da, new PropertyPath(property));
            Storyboard.SetTarget(da, element);
            return da;
        }
    }
}</pre></div></div>

<p>For the most part the code is very simmiler to the other trigger.  When you inherate from TargetTriggerAction you gain access to a new property called &#8220;Target&#8221; this will contain a reference to the UIELement I plan on flipping.  Instead of adding my PlainProjection to the AssociatedObject I instead add it to the target.  I made a few other changes like storing my Storyboards as dependency properties which allow me to reuse the same animiation each time I lick the button.  These DependencyProperites get stored in the AssociatedObject and not the Target.  This allows each item being clicked to have a unique animation.  Below is how I implement the TargetTriggerAction.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">&lt;StackPanel Orientation=&quot;Vertical&quot;&gt;
    &lt;Grid Margin=&quot;10&quot; x:Name=&quot;flipMe&quot;&gt;
        &lt;StackPanel x:Name=&quot;back1&quot; Height=&quot;200&quot; Width=&quot;200&quot; HorizontalAlignment=&quot;Center&quot; 
                    VerticalAlignment=&quot;Center&quot;&gt;
            &lt;Rectangle Fill=&quot;Green&quot; Height=&quot;200&quot; Width=&quot;200&quot; StrokeThickness=&quot;1&quot; Stroke=&quot;Black&quot; /&gt;
        &lt;/StackPanel&gt;
        &lt;Rectangle x:Name=&quot;front1&quot; Fill=&quot;Gold&quot; Height=&quot;200&quot; Width=&quot;200&quot; 
                   HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;/&gt;
    &lt;/Grid&gt;
    &lt;Button Content=&quot;Flip RightToLeft&quot; Width=&quot;100&quot;&gt;
        &lt;i:Interaction.Triggers&gt;
            &lt;i:EventTrigger EventName=&quot;Click&quot;&gt;
                &lt;targeted:Flip FrontElementName=&quot;front1&quot; BackElementName=&quot;back1&quot; 
                               TargetName=&quot;flipMe&quot; Duration=&quot;00:00:1&quot; Rotation=&quot;RightToLeft&quot;/&gt;
            &lt;/i:EventTrigger&gt;
        &lt;/i:Interaction.Triggers&gt;
    &lt;/Button&gt;
    &lt;Button Content=&quot;Flip TopToBtoom&quot; Width=&quot;100&quot;&gt;
        &lt;i:Interaction.Triggers&gt;
            &lt;i:EventTrigger EventName=&quot;Click&quot;&gt;
                &lt;targeted:Flip FrontElementName=&quot;front1&quot; BackElementName=&quot;back1&quot; 
                               TargetName=&quot;flipMe&quot; Duration=&quot;00:00:1&quot; Rotation=&quot;TopToBottom&quot;/&gt;
            &lt;/i:EventTrigger&gt;
        &lt;/i:Interaction.Triggers&gt;
    &lt;/Button&gt;
&lt;/StackPanel&gt;</pre></div></div>

<p><br style="clear:both"/><br />
<iframe src="/wp-content/uploads/2009/08/FlipTargetedTrigger/" width="500" height="300"></iframe><br />
Code: <a onclick="javascript: pageTracker._trackPageview('/code/FlipTargetedTrigger.zip'); " href="/wp-content/uploads/2009/08/FlipTargetedTrigger/FlipTargetedTrigger.zip">FlipTargetedTrigger.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/08/silverlight-3-flip-targetedtriggeraction/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Silverlight 3 Flip TriggerAction</title>
		<link>http://joel.neubeck.net/2009/07/silverlight-3-flip-triggeraction/</link>
		<comments>http://joel.neubeck.net/2009/07/silverlight-3-flip-triggeraction/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 18:26:23 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[3D Flip]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[System.Windows.Interactivity]]></category>
		<category><![CDATA[TiggerAction]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=417</guid>
		<description><![CDATA[In this blog post I am going to create a TriggerAction which makes it incredibly simple to take two UIElements and compose them into a panel which can be flipped. I have demonstrated the technique many times, but here it is all packaged up in a nice reusable class. The following is the code I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://joel.neubeck.net/wp-content/uploads/2009/07/flip1.PNG"><img src="http://joel.neubeck.net/wp-content/uploads/2009/07/flip1-300x154.PNG" alt="flip1" title="flip1" width="300" height="154" class="alignleft size-medium wp-image-418" /></a>In this blog post I am going to create a TriggerAction which makes it incredibly simple to take two UIElements and compose them into a panel which can be flipped.  I have demonstrated the technique many times, but here it is all packaged up in a nice reusable class.</p>
<p> The following is the code I used to create by Flip TriggerAction.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Interactivity;
using System.ComponentModel;
&nbsp;
namespace FlipTriggerAction
{
    public enum RotationDirection
    {
        LeftToRight,
        RightToLeft,
        TopToBottom,
        BottomToTop
    }
&nbsp;
    public class Flip : TriggerAction&lt;FrameworkElement&gt;
    {
        public static readonly DependencyProperty FrontElementNameProperty =
            DependencyProperty.Register(&quot;FrontElementName&quot;, typeof(string),
                                        typeof(Flip), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Flip Properties&quot;)]
        public string FrontElementName { get; set; }
&nbsp;
        public static readonly DependencyProperty BackElementNameProperty =
            DependencyProperty.Register(&quot;BackElementName&quot;, typeof(string),
                                        typeof(Flip), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Flip Properties&quot;)]
        public string BackElementName { get; set; }
&nbsp;
        public static readonly DependencyProperty DurationProperty =
            DependencyProperty.Register(&quot;Duration&quot;, typeof(Duration),
                                        typeof(Flip), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Animation Properties&quot;)]
        public Duration Duration { get; set; }
&nbsp;
        public static readonly DependencyProperty RotationProperty =
            DependencyProperty.Register(&quot;Rotation&quot;, typeof(RotationDirection),
                                        typeof(Flip), new PropertyMetadata(RotationDirection.LeftToRight));
&nbsp;
        [Category(&quot;Animation Properties&quot;)]
        public RotationDirection Rotation { get; set; }
&nbsp;
        private readonly Storyboard _sbF = new Storyboard();
        private readonly Storyboard _sbB = new Storyboard();
        private bool _forward = true;
&nbsp;
        protected override void Invoke(object parameter)
        {
            if (AssociatedObject.Projection == null)
            {
                FrameworkElement parent = AssociatedObject as FrameworkElement;
                UIElement f = null;
                UIElement b = null;
&nbsp;
                if (parent != null)
                {
                    f = parent.FindName(FrontElementName) as UIElement;
                    if (f != null)
                    {
                        PlaneProjection ppFront = new PlaneProjection { CenterOfRotationY = .51 };
                        f.Projection = ppFront;
                        f.RenderTransformOrigin = new Point(.5, .5);
                    }
                    b = parent.FindName(BackElementName) as UIElement;
                    if (b != null)
                    {
                        PlaneProjection ppBack = new PlaneProjection { CenterOfRotationY = .51, RotationY = 180.0 };
                        b.Projection = ppBack;
                        b.RenderTransformOrigin = new Point(.5, .5);
                        b.Opacity = 0.0;
                    }
                }
&nbsp;
                PlaneProjection pp = new PlaneProjection { CenterOfRotationY = .51 };
&nbsp;
                AssociatedObject.RenderTransformOrigin = new Point(.5, .5);
                AssociatedObject.Projection = pp;
&nbsp;
                double to = 180.0;
                double from = 0.0;
                string property = &quot;RotationY&quot;;
&nbsp;
                switch (Rotation)
                {
                    case RotationDirection.RightToLeft:
                        to = 0.0;
                        from = 180.0;
                        break;
                    case RotationDirection.TopToBottom:
                        property = &quot;RotationX&quot;;
                        break;
                    case RotationDirection.BottomToTop:
                        to = 0.0;
                        from = 180.0;
                        property = &quot;RotationX&quot;;
                        break;
                }
&nbsp;
                _sbF.Duration = Duration;
                _sbB.Duration = Duration;
&nbsp;
                _sbF.Children.Add(CreateDoubleAnimation(pp, property, from, to, true));
                _sbB.Children.Add(CreateDoubleAnimation(pp, property, to, from, true));
&nbsp;
                _sbF.Children.Add(CreateDoubleAnimation(f, &quot;Opacity&quot;, 1.0, 0.0, false));
                _sbB.Children.Add(CreateDoubleAnimation(f, &quot;Opacity&quot;, 0.0, 1.0, false));
&nbsp;
                _sbF.Children.Add(CreateDoubleAnimation(b, &quot;Opacity&quot;, 0.0, 1.0, false));
                _sbB.Children.Add(CreateDoubleAnimation(b, &quot;Opacity&quot;, 1.0, 0.0, false));
            }
            if (_forward)
            {
                _sbF.Begin();
                _forward = false;
            }
            else
            {
                _sbB.Begin();
                _forward = true;
            }
        }
&nbsp;
        private static DoubleAnimation CreateDoubleAnimation(DependencyObject element, string property, double from,
                                                             double to, bool addEasing)
        {
            DoubleAnimation da = new DoubleAnimation();
            da.To = to;
            da.From = from;
            if (addEasing)
                da.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseOut, Power = 3 };
&nbsp;
&nbsp;
            Storyboard.SetTargetProperty(da, new PropertyPath(property));
            Storyboard.SetTarget(da, element);
            return da;
        }
    }
}</pre></div></div>

<p>Once you have the class constructed you can add the trigger to your UIElement in Blend.  Clicking on the trigger in the Object &#038; Timeline tab will allow you to configure each of the the properties you have defined in your class.<br />
<a href="http://joel.neubeck.net/wp-content/uploads/2009/07/flip2.PNG"><img src="http://joel.neubeck.net/wp-content/uploads/2009/07/flip2-300x205.PNG" alt="flip2" title="flip2" width="300" height="205" class="aligncenter size-medium wp-image-419" /></a><br style="clear:both"/><br />
<iframe src="/wp-content/uploads/2009/07/FlipTriggerAction/" width="500" height="300"></iframe><br />
Code: <a onclick="javascript: pageTracker._trackPageview('/code/FlipTriggerAction.zip'); " href="/wp-content/uploads/2009/07/FlipTriggerAction/FlipTriggerAction.zip">FlipTriggerAction.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/07/silverlight-3-flip-triggeraction/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Silverlight 3 Drag Behavior</title>
		<link>http://joel.neubeck.net/2009/07/silverlight-3-drag-behavior/</link>
		<comments>http://joel.neubeck.net/2009/07/silverlight-3-drag-behavior/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 17:35:53 +0000</pubDate>
		<dc:creator>joel</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Blend]]></category>
		<category><![CDATA[Interaction.Behaviors]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[System.Windows.Interactivity]]></category>

		<guid isPermaLink="false">http://joel.neubeck.net/?p=406</guid>
		<description><![CDATA[By now most Silverlight developers should have stumbled on a great new feature of Silverlight 3 and Expression Blends, custom Triggers and Behaviors. I seriously don&#8217;t know how I lived without them! In this blog post I am going to demonstrate a simple, yet useful, example of a behavior which allows a UIElement to become [...]]]></description>
			<content:encoded><![CDATA[<p>By now most Silverlight developers should have stumbled on a great new feature of Silverlight 3 and Expression Blends, custom Triggers and Behaviors. I seriously don&#8217;t know how I lived without them!</p>
<p><a href="http://joel.neubeck.net/wp-content/uploads/2009/07/drag_1.PNG"><img class="alignleft size-medium wp-image-410" title="drag_1" src="http://joel.neubeck.net/wp-content/uploads/2009/07/drag_1-300x203.PNG" alt="drag_1" width="300" height="203" /></a>In this blog post I am going to demonstrate a simple, yet useful, example of a behavior which allows a UIElement to become drag able. Figure 1 show the view of my XAML from within Blend. For this example I will create an image with a rounded border which has been placed within a Grid. In the center of my grid I have a Red Rectangle.<br style="clear:both" /><br />
To create my Behavior I will jump in to VS2008 and create a new class that will reside within my solution. If my goal was to create a collection of generic behaviors and triggers I would likely create a Silverlight class assembly and deploy it to the library folder within Blend. This would allow my custom behaviors to be available to all Silverlight or WPF project. The following demonstrates the code I used to create by Drag behavior.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Interactivity;
using System.Windows.Media.Imaging;
&nbsp;
namespace DragBehaviors
{
    public class Drag : Behavior
    {
        public static readonly DependencyProperty IsMovableProperty =
            DependencyProperty.Register(&quot;IsMovable&quot;, typeof(bool),
                                        typeof(Drag), new PropertyMetadata(null));
&nbsp;
        [Category(&quot;Target Properties&quot;)]
        public bool IsMovable { get; set; }
&nbsp;
        private bool _isDragging = false;
        private Point _offset;
        private readonly TranslateTransform _elementTranslate = new TranslateTransform();
        private TranslateTransform _imgTranslate = new TranslateTransform();
        private Image _img = new Image();
&nbsp;
        protected override void OnAttached()
        {
            base.OnAttached();
&nbsp;
            AssociatedObject.Loaded += AssociatedObjectLoaded;
            AssociatedObject.HorizontalAlignment = HorizontalAlignment.Left;
            AssociatedObject.VerticalAlignment = VerticalAlignment.Top;
            AssociatedObject.MouseLeftButtonDown += AssociatedObjectMouseLeftButtonDown;
        }
&nbsp;
        void AssociatedObjectLoaded(object sender, RoutedEventArgs e)
        {
            AssociatedObject.RenderTransform = _elementTranslate;
        }
&nbsp;
        protected override void OnDetaching()
        {
            base.OnDetaching();
            AssociatedObject.MouseLeftButtonDown -= AssociatedObjectMouseLeftButtonDown;
        }
&nbsp;
        private void AssociatedObjectMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (!_isDragging) return;
            FrameworkElement parent = _img.Parent as FrameworkElement;
            Point newPosition = e.GetPosition(parent);
&nbsp;
            // Move the dragon via the new position less the offset
            _imgTranslate.X = (newPosition.X - _offset.X);
            _imgTranslate.Y = (newPosition.Y - _offset.Y);
        }
&nbsp;
        private void AssociatedObjectMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (!_isDragging) return;
            Panel panel = AssociatedObject.Parent as Panel;
&nbsp;
            // turn off drag
            _isDragging = false;
&nbsp;
            // Free the Mouse
            _img.ReleaseMouseCapture();
            _img.MouseMove -= AssociatedObjectMouseMove;
            _img.MouseLeftButtonUp -= AssociatedObjectMouseLeftButtonUp;
&nbsp;
            if (IsMovable)
            {
                _elementTranslate.X = _imgTranslate.X;
                _elementTranslate.Y = _imgTranslate.Y;
            }
            _imgTranslate = new TranslateTransform();
            _offset = new Point(0, 0);
            AssociatedObject.Opacity = 1;
            if (panel != null) panel.Children.Remove(_img);
            _img = new Image();
        }
&nbsp;
        private void AssociatedObjectMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _isDragging = true;
&nbsp;
            AssociatedObject.Opacity = .35;
&nbsp;
            WriteableBitmap bitmap = new WriteableBitmap(AssociatedObject, new TranslateTransform());
            if (_img == null) return;
&nbsp;
            _img.Source = bitmap;
            _img.HorizontalAlignment = HorizontalAlignment.Left;
            _img.VerticalAlignment = VerticalAlignment.Top;
            _img.Stretch = Stretch.None;
            _img.Width = bitmap.PixelWidth;
            _img.Height = bitmap.PixelHeight;
&nbsp;
            _imgTranslate.X = _elementTranslate.X;
            _imgTranslate.Y = _elementTranslate.Y;
&nbsp;
            _img.RenderTransform = _imgTranslate;
            _img.MouseMove += AssociatedObjectMouseMove;
            _img.MouseLeftButtonUp += AssociatedObjectMouseLeftButtonUp;
&nbsp;
            Panel panel = AssociatedObject.Parent as Panel;
&nbsp;
            if (panel != null) panel.Children.Add(_img);
&nbsp;
            _offset = e.GetPosition(_img);
            _img.CaptureMouse();
        }
    }
}</pre></div></div>

<p>For the most part the code should be self explanatory. One cool thing I did was that when I first begin dragging the UIElement, I convert it to a Bitmap and drag an image. The idea is that it will be more efficient to move a image around the screen then the actual collection of UIElements. Once I drop the image than I physically move the UIElement. Note that in its current state this only works correctly if the UIElement I am dragging is Left and Top aligned. This ensures that it is sitting at X=0, Y=0 in the panel it is residing. My guess is that it could be rewritten to support other alignments.</p>
<p>Once the Behavior class is constructed we simply add it to the control we want to drag.</p>

<div class="wp_syntax"><div class="code"><pre class="c-sharp" style="font-family:monospace;">&lt;Border BorderThickness=&quot;1&quot; BorderBrush=&quot;Black&quot; CornerRadius=&quot;6&quot; 
    HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;&gt;
    &lt;i:Interaction.Behaviors&gt;
        &lt;behaviors:Drag IsMovable=&quot;True&quot;/&gt;
    &lt;/i:Interaction.Behaviors&gt;
    &lt;Grid&gt;
        &lt;Image Source=&quot;4.jpg&quot; Width=&quot;100&quot; Height=&quot;100&quot; Stretch=&quot;UniformToFill&quot;/&gt;
        &lt;TextBlock Text=&quot;Image&quot; FontWeight=&quot;Bold&quot; FontSize=&quot;20&quot; 
            Foreground=&quot;Black&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;/&gt;
    &lt;/Grid&gt;
&lt;/Border&gt;</pre></div></div>

<p><iframe src="/wp-content/uploads/2009/07/DragBehavior/" width="500" height="300"></iframe><br />
Code: <a onclick="javascript: pageTracker._trackPageview('/code/DragBehavior.zip'); " href="/wp-content/uploads/2009/07/DragBehavior/DragBehavior.zip">DragBehavior.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joel.neubeck.net/2009/07/silverlight-3-drag-behavior/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

