<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Adrian Vinca's blog : Tutorials</title><link>http://blogs.msdn.com/adrianvinca/archive/tags/Tutorials/default.aspx</link><description>Tags: Tutorials</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to use a custom ValueConverter in Microsoft Expression Interactive Designer</title><link>http://blogs.msdn.com/adrianvinca/archive/2006/03/10/538409.aspx</link><pubDate>Fri, 10 Mar 2006 04:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:538409</guid><dc:creator>adrianvinca</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/adrianvinca/comments/538409.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adrianvinca/commentrss.aspx?PostID=538409</wfw:commentRss><description>One of the new databinding features in the March CTP of &lt;a href="http://www.microsoft.com/products/expression/en/interactive_designer/default.mspx"&gt;Microsoft Expression Interactive Designer&lt;/a&gt; is the ability to handle value converters. This article will explain how to databind 2 TextBox controls using a custom value converter which reverts the text. 
&lt;H4&gt;Step 1 - Create a custom value converter &lt;/H4&gt;We will create a very simple value converter which reverts a string. We will define the custom converter class in the code behind file for Scene1. &lt;BR&gt;So, copy paste the following code into the codebehind file (&lt;B&gt;scene1.xaml.cs&lt;/B&gt;), after the closing tag for the Scene1 class. &lt;PRE&gt;	[ValueConversion(typeof(string), typeof(string))]
	public class ReverseStringConverter: IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			string source = value as string;
			return ReverseStringConverter.RevertString(source);
		}
 
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			string source = value as string;
			return ReverseStringConverter.RevertString(source);
		}
	
		private static string RevertString(string source)
		{
			int sourceLength = source.Length;
			char[] destination = new char[source.Length];
			
			for (int iterator = 0; iterator &amp;lt; sourceLength; iterator++)
			{
				destination[iterator] = source[sourceLength - iterator - 1];
			}
			
			return new string(destination);
		}
	}
&lt;/PRE&gt;The class ReverseStringConverter implements the &lt;A href="http://windowssdk.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref30/html/t_system_windows_data_ivalueconverter.asp"&gt;IValueConverter&lt;/A&gt; converter interface (click the link for more information). In our example, both methods, &lt;STRONG&gt;Convert&lt;/STRONG&gt; and &lt;STRONG&gt;ConvertBack&lt;/STRONG&gt; call the same private method &lt;STRONG&gt;RevertString&lt;/STRONG&gt; which reverts&amp;nbsp;the specified&amp;nbsp;string. &lt;BR&gt;
&lt;H4&gt;Step 2 - Build project&lt;/H4&gt;Currently &lt;a href="http://www.microsoft.com/products/expression/en/interactive_designer/default.mspx"&gt;Microsoft Expression Interactive Designer&lt;/a&gt; requires the project to be built in order to use classed defined in the project. For that, in the main menu click on &lt;STRONG&gt;Project&lt;/STRONG&gt; -&amp;gt; &lt;STRONG&gt;Build Project&lt;/STRONG&gt; 
&lt;H4&gt;Step 3 - Create 2 TextBox controls in the scene&lt;/H4&gt;Switch to the Scene1.&lt;BR&gt;Bring up the Properties palette and create 2 TextBox controls in the scene. 
&lt;H4&gt;Step 4 - Create the databinding using the custom value converter&lt;/H4&gt;We are going to databind the &lt;STRONG&gt;Text&lt;/STRONG&gt; property of &lt;STRONG&gt;TextBox&lt;/STRONG&gt; to the &lt;STRONG&gt;Text&lt;/STRONG&gt; property of &lt;STRONG&gt;TextBox1&lt;/STRONG&gt;, using the custom value converter defined previously (ReverseStringConverter). Select the first TextBox (named TextBox) using the Selection tool.&lt;BR&gt;In the &lt;STRONG&gt;Properties&lt;/STRONG&gt; palette, click on the &lt;STRONG&gt;Text&lt;/STRONG&gt; property and select "&lt;STRONG&gt;Databind&lt;/STRONG&gt;" from the menu. The &lt;STRONG&gt;Create Data Binding&lt;/STRONG&gt; dialog will be displayed.&lt;BR&gt;Click on the "&lt;STRONG&gt;Element Property&lt;/STRONG&gt;". &lt;STRONG&gt;&lt;FONT style="BACKGROUND-COLOR: #ffffff" color=#ff0000&gt;A&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;Select &lt;STRONG&gt;TextBox1&lt;/STRONG&gt; from the &lt;STRONG&gt;Scene Elements&lt;/STRONG&gt; section &lt;STRONG&gt;&lt;FONT color=#ff0000&gt;B&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;Select &lt;STRONG&gt;Text&lt;/STRONG&gt; from the &lt;STRONG&gt;Properties&lt;/STRONG&gt; section. &lt;STRONG&gt;&lt;FONT color=#ff0000&gt;C&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;Click on "&lt;STRONG&gt;More Binding Options&lt;/STRONG&gt;" expand button; this will show a few more advanced binding options. &lt;BR&gt;Click on the double arrow button to set the &lt;STRONG&gt;Binding Direction&lt;/STRONG&gt; as &lt;STRONG&gt;Two Way&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color=#ff0000&gt;D&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR&gt;Click on the "&lt;STRONG&gt;...&lt;/STRONG&gt;" button &lt;STRONG&gt;&lt;FONT color=#ff0000&gt;E&lt;/FONT&gt;&lt;/STRONG&gt; next to the &lt;STRONG&gt;ValueConverter&lt;/STRONG&gt;; the "&lt;STRONG&gt;Add value converter&lt;/STRONG&gt;" dialog will be displayed &lt;BR&gt;Expand the node coresponding to your project and select "&lt;STRONG&gt;ReverseStringConverter&lt;/STRONG&gt;" from there. Press on the &lt;STRONG&gt;OK&lt;/STRONG&gt; Button.&lt;BR&gt;At this point, the &lt;STRONG&gt;Create Data Binding&lt;/STRONG&gt; dialog should look like this: &lt;BR&gt;&lt;IMG src="/photos/adrianvinca/images/original/CreateDataBindingDialog.aspx" border=0&gt;&lt;BR&gt;Press the &lt;STRONG&gt;Finish&lt;/STRONG&gt; button &lt;BR&gt;
&lt;H4&gt;Step 5 - Build and run the application&lt;/H4&gt;For that, go into the main menu and select &lt;STRONG&gt;Project&lt;/STRONG&gt;-&amp;gt;&lt;STRONG&gt;Test Project&lt;/STRONG&gt;. &lt;a href="http://www.microsoft.com/products/expression/en/interactive_designer/default.mspx"&gt;Microsoft Expression Interactive Designer&lt;/a&gt; should build your application and a new window should be displayed &lt;BR&gt;Type in the first textbox. You notice that the text is automatically updated in the second textbox (and it is reverted). &lt;BR&gt;If you type in the second textbox, the first textbox will be updated &lt;BR&gt;. &lt;IMG src="/photos/adrianvinca/images/538418/561x480.aspx" border=0&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=538409" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Expression+Blend/default.aspx">Expression Blend</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Tutorials/default.aspx">Tutorials</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Expression/default.aspx">Expression</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Designer+Tools/default.aspx">Designer Tools</category></item><item><title>Creating a simple style with one trigger</title><link>http://blogs.msdn.com/adrianvinca/archive/2006/02/16/532949.aspx</link><pubDate>Thu, 16 Feb 2006 05:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:532949</guid><dc:creator>adrianvinca</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/adrianvinca/comments/532949.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adrianvinca/commentrss.aspx?PostID=532949</wfw:commentRss><description>&lt;P&gt;This article describes how to create a simple style with one trigger in &lt;a href="http://www.microsoft.com/products/expression/en/interactive_designer/default.mspx"&gt;Microsoft Expression Interactive Designer&lt;/a&gt;. We will create a blue rectangle which becomes red when the mouse is over it.&lt;/P&gt;
&lt;H4&gt;Step 1 - Create a rectangle&lt;/H4&gt;
&lt;P&gt;Draw a rectangle using the "&lt;STRONG&gt;Rectangle&lt;/STRONG&gt;" tool from the Tools palette&lt;BR&gt;Click on the "&lt;STRONG&gt;Selection&lt;/STRONG&gt;" tool on the tools palette&lt;/P&gt;
&lt;H4&gt;Step 2 - Clear the Fill property&lt;/H4&gt;
&lt;P&gt;EID by default sets a Fill to your rectangle which would override our Style settings, so we need to delete that property (if you switch to the xaml view, you will notice that there is a Fill attribute specified for the rectangle): &lt;BR&gt;In the &lt;STRONG&gt;Properties&lt;/STRONG&gt; palette, Click on the &lt;STRONG&gt;Fill&lt;/STRONG&gt; property and Select "&lt;STRONG&gt;Clear/Default&lt;/STRONG&gt;" - &lt;BR&gt;this should clear the property&lt;/P&gt;
&lt;H4&gt;Step 3 - Create a Style for the rectangle&lt;/H4&gt;
&lt;P&gt;In the timeline, right click on your rectangle-&amp;gt;&lt;STRONG&gt;Edit Style&lt;/STRONG&gt;-&amp;gt;&lt;STRONG&gt;Create Empty Style &lt;/STRONG&gt;(usually you should be able to do this in the scene, but now, because the Fill property is not set, the rectangle&amp;nbsp;may not selectable in the scene - known issue)&lt;/P&gt;
&lt;P&gt;Click "&lt;STRONG&gt;Ok&lt;/STRONG&gt;" in the "&lt;STRONG&gt;Create Style Resource&lt;/STRONG&gt;" dialog&lt;/P&gt;
&lt;H4&gt;Step 4 - Set a default Fill for the rectangle inside the Style&lt;/H4&gt;
&lt;P&gt;Bring up the "&lt;STRONG&gt;Timeline&lt;/STRONG&gt;" palette - note that we are currently editing the style (the node displayed should be "Style"). In order to get the mouse events at runtime, our rectangle will need a Fill; so we will set a Fill in the Style.&lt;/P&gt;
&lt;P&gt;In the &lt;STRONG&gt;Appearance&lt;/STRONG&gt; palette, set the &lt;STRONG&gt;Fill&lt;/STRONG&gt; to "blue" (because we are in the Style editing mode, this will create a Setter inside the style)&lt;/P&gt;
&lt;H4&gt;Step 5 - Add a Trigger&amp;nbsp;for the IsMouseOver&lt;/H4&gt;Click on the "&lt;STRONG&gt;Create New State&lt;/STRONG&gt;" button; a new tab called "&lt;STRONG&gt;[No Triggers]&lt;/STRONG&gt;" is displayed in the timeline; Click on it &lt;BR&gt;Bring up the "&lt;STRONG&gt;Timeline Properties&lt;/STRONG&gt;" palette (using the "View" menu)&lt;BR&gt;Create a new trigger: Click on the "&lt;STRONG&gt;Add&lt;/STRONG&gt;" button in the "&lt;STRONG&gt;Timeline Properties&lt;/STRONG&gt;" to add a new trigger; in the first textbox type "&lt;STRONG&gt;IsMouseOver&lt;/STRONG&gt;" and "&lt;STRONG&gt;true&lt;/STRONG&gt;" in the second one; now the tab is called "&lt;STRONG&gt;IsMouseOver&lt;/STRONG&gt;"&lt;BR&gt;Ensure that the "&lt;STRONG&gt;IsMouseOver&lt;/STRONG&gt;" tab is selected and change the "Fill" color in the "Appearance" palette to your desired color (e.g. "red")&lt;BR&gt;Click the "&lt;STRONG&gt;Return Scope To Root&lt;/STRONG&gt;" button (in the Timeline palette) to end the style editing mode&lt;BR&gt;&lt;BR&gt;
&lt;H4&gt;The final xaml&lt;/H4&gt;The final xaml looks like:
&lt;pre&gt;
	&amp;lt;Grid.Resources&gt;
		&amp;lt;Storyboard x:Key="OnLoaded"/&gt;
		&amp;lt;Style x:Key="RectangleStyle1" TargetType="{x:Type Rectangle}"&gt;
			&amp;lt;Setter Property="Fill" Value="sc#1, 0, 0, 1"/&gt;
			&amp;lt;Style.Triggers&gt;
				&amp;lt;MultiTrigger&gt;
					&amp;lt;MultiTrigger.Conditions&gt;
						&amp;lt;Condition Property="IsMouseOver" Value="True"/&gt;
					&amp;lt;/MultiTrigger.Conditions&gt;
					&amp;lt;Setter Property="Fill" Value="sc#1, 1, 0, 0"/&gt;
				&amp;lt;/MultiTrigger&gt;
			&amp;lt;/Style.Triggers&gt;
		&amp;lt;/Style&gt;
	&amp;lt;/Grid.Resources&gt;
&lt;/pre&gt;

&lt;pre&gt;
&amp;lt;Rectangle Stroke="#FF000000" Style="{DynamicResource RectangleStyle1}"
	Width="Auto" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
	MinWidth="0" MinHeight="0" Margin="128,99,183,202" x:Name="Rectangle"
	RenderTransformOrigin="0.5,0.5"/&gt;
&lt;/pre&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=532949" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Expression+Blend/default.aspx">Expression Blend</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Tutorials/default.aspx">Tutorials</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Expression/default.aspx">Expression</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Designer+Tools/default.aspx">Designer Tools</category></item><item><title>Creating a simple master details list</title><link>http://blogs.msdn.com/adrianvinca/archive/2006/02/15/532449.aspx</link><pubDate>Wed, 15 Feb 2006 13:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:532449</guid><dc:creator>adrianvinca</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/adrianvinca/comments/532449.aspx</comments><wfw:commentRss>http://blogs.msdn.com/adrianvinca/commentrss.aspx?PostID=532449</wfw:commentRss><description>&lt;P&gt;This article describes how to create a master details list using &lt;a href="http://www.microsoft.com/products/expression/en/interactive_designer/default.mspx"&gt;Microsoft Expression Interactive Designer&lt;/a&gt; (and guess what: no code needed!). We are going to use databinding to achieve this.&lt;/P&gt;
&lt;H4&gt;The data-source&lt;/H4&gt;
&lt;P&gt;We will use a simple xml, containing the list of products from the Expression family, and a short description for each of them. Download the attached "&lt;STRONG&gt;products.xml&lt;/STRONG&gt;" and save it on your local machine. &lt;/P&gt;
&lt;P&gt;Start &lt;a href="http://www.microsoft.com/products/expression/en/interactive_designer/default.mspx"&gt;Microsoft Expression Interactive Designer&lt;/a&gt;. We will use the empty project created by default &lt;/P&gt;
&lt;P&gt;Add &lt;STRONG&gt;products.xml&lt;/STRONG&gt; as an XML Data source. For that, in the "&lt;STRONG&gt;Data&lt;/STRONG&gt;" palette, click on the "&lt;STRONG&gt;Add XML Data Source&lt;/STRONG&gt;" and Browse to the "&lt;STRONG&gt;products.xml&lt;/STRONG&gt;". Press &lt;STRONG&gt;Ok&lt;/STRONG&gt;. Now the Data Palette will show the new data source (its default name is "&lt;STRONG&gt;ProductsDS&lt;/STRONG&gt;").&lt;/P&gt;
&lt;H4&gt;The master list&lt;/H4&gt;
&lt;P&gt;Expand the "&lt;STRONG&gt;ProductsDS&lt;/STRONG&gt;" data source and "&lt;STRONG&gt;Product[n]&lt;/STRONG&gt;" node on the scene. Choose &lt;STRONG&gt;ListBox&lt;/STRONG&gt; from the context menu. Press "&lt;STRONG&gt;Ok&lt;/STRONG&gt;" at the first dialog; in the second one, uncheck "&lt;STRONG&gt;Description&lt;/STRONG&gt;" (we want to show only the name in the list) and press &lt;STRONG&gt;Ok&lt;/STRONG&gt;. At this point, you should have a list displaying the names of the products.&lt;/P&gt;
&lt;H4&gt;The details&lt;/H4&gt;
&lt;P&gt;We want to display the description of the selected item in a separate TextBox.&lt;/P&gt;
&lt;P&gt;Create a &lt;STRONG&gt;TextBlock&lt;/STRONG&gt; control from the &lt;STRONG&gt;Library&lt;/STRONG&gt; Palette&lt;/P&gt;
&lt;P&gt;In the "&lt;STRONG&gt;Properties&lt;/STRONG&gt;" palette, click on the "&lt;STRONG&gt;Data Context&lt;/STRONG&gt;" property and select "&lt;STRONG&gt;Databind&lt;/STRONG&gt;". Click on the "&lt;STRONG&gt;Element Property&lt;/STRONG&gt;" button, select the "&lt;STRONG&gt;ListBox&lt;/STRONG&gt;" as the scene element (left side) and "&lt;STRONG&gt;Selected Item&lt;/STRONG&gt;" as the property (right side). Press "&lt;STRONG&gt;Finish&lt;/STRONG&gt;". This way we set the Data Context to the Selected Item of the Listbox.&lt;/P&gt;
&lt;P&gt;In the "&lt;STRONG&gt;Properties&lt;/STRONG&gt;" palette, click on the "&lt;STRONG&gt;Text&lt;/STRONG&gt;" property and select "&lt;STRONG&gt;Databind&lt;/STRONG&gt;". Click on the "&lt;STRONG&gt;Explicit Data Context&lt;/STRONG&gt;" button and expand the tree and select "&lt;STRONG&gt;Description&lt;/STRONG&gt;". Press &lt;STRONG&gt;Finish&lt;/STRONG&gt;. This way we specify what exactly we want to display as the Text.&lt;/P&gt;
&lt;H4&gt;Run the project&lt;/H4&gt;
&lt;P&gt;The only thing left: run the project (In the main menu, Project click on "Run Project"). The application will be compiled and executed. The Description textbox shows the Description of the selected item.&lt;/P&gt;
&lt;H4&gt;Why is the textbox empty in Expression Interactive Designer ?&lt;/H4&gt;
&lt;P&gt;That's because, by default, there is no item selected in the list. To do that, select the listbox and set the &lt;STRONG&gt;SelectedIndex&lt;/STRONG&gt; property to 0 (by default it is -1).&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=532449" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/adrianvinca/attachment/532449.ashx" length="1032" type="text/xml" /><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Expression+Blend/default.aspx">Expression Blend</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Tutorials/default.aspx">Tutorials</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Expression/default.aspx">Expression</category><category domain="http://blogs.msdn.com/adrianvinca/archive/tags/Designer+Tools/default.aspx">Designer Tools</category></item></channel></rss>