<?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>xaml ninja &#187; Silverlight</title>
	<atom:link href="http://blogs.xamlninja.com/category/silverlight/feed" rel="self" type="application/rss+xml" />
	<link>http://blogs.xamlninja.com</link>
	<description>xaml ninja moves</description>
	<lastBuildDate>Tue, 10 Jan 2012 19:46:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>uk tech.days 2011</title>
		<link>http://blogs.xamlninja.com/silverlight/uk-tech-days-2011</link>
		<comments>http://blogs.xamlninja.com/silverlight/uk-tech-days-2011#comments</comments>
		<pubDate>Mon, 23 May 2011 12:31:12 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[uktechdays]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=464</guid>
		<description><![CDATA[This week Ollie and I will presenting at the UK tech.days happening in the Fulham, London. Our first session will be all about building Data Data Intensive apps for WP7 and we are really looking forward to talking to you about what we have learnt building these types of applications. We are also going to [...]]]></description>
			<content:encoded><![CDATA[<p>This week <a href="http://awkwardcoder.blogspot.com/" target="_blank">Ollie </a>and I will presenting at the UK <a href="http://uktechdays.cloudapp.net/home.aspx">tech.days</a> happening in the Fulham, London.</p>
<p>Our first session will be all about building <a href="http://uktechdays.cloudapp.net/techdays-live/windows-phone-1-state-of-the-nation.aspx" target="_blank">Data Data Intensive apps for WP7</a> and we are really looking forward to talking to you about what we have learnt building these types of applications. We are also going to show off bits from the WP7 Contrib that help to make building these types of applications easier. It&#8217;s going to be a demo packed session so hold on for a rollercoaster ride. We are making avaliable all our demos before the session so if you are attending and interested you can download these from the skydrive link at the bottom of the post.</p>
<p>My other session obviously will be about using Blend =P  and the title of the session is aptly named <a href="http://uktechdays.cloudapp.net/techdays-live/building-rich-client-applications.aspx">&#8220;Expression Blend for Silverlight Developers&#8221;</a>.</p>
<p>The session is broken down into 3 sub sections; designer developer collaboration; Blend quick fire tips; and the main part, building out an app from a Adobe Photoshop/Illustrator visual design into a functional Silverlight app. This session is aimed particularly at developers who are just starting out with Blend, however even if you have been using Blend for a while there should be plenty of refreshers.</p>
<p>Now, I had thought about doing</p>
<p><em> “… this is how I create a button in Blend, and oh look I can make it into a circle and bounce across the screen…”</em></p>
<p>as much as I love attending these sessions and love the buzz afterwards sometimes it can be difficult to relate the content to a problem you may currently be working on.</p>
<p>Up on skydrive you will find; the .psd file I am going to use; an unstyled version; and a completed version that is styled. There is still plenty more to do so the scope is open and hopefully you will be able to use this as a reference point for future apps that you build. Therefore, I thought that it would be an interesting idea to see how attendees if they so wished can use the session as a hands-on Blend training hour, and if you want to participate then you can. Otherwise you can sit back and watch how we build a static vector graphic into a functioning app.</p>
<p>If you are planning on attending and would like me to cover off anything in particular I will do my best to make it happen, otherwise I would be more than happy to chat during the event, if you can bring code or have a scenario that would really help me understand the context of your questions.</p>
<p>You can find all of the goodies up on the sky drive folder.</p>
<p>See you there!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/uk-tech-days-2011/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The cleansing process</title>
		<link>http://blogs.xamlninja.com/uncategorized/the-cleansing-process</link>
		<comments>http://blogs.xamlninja.com/uncategorized/the-cleansing-process#comments</comments>
		<pubDate>Wed, 13 Oct 2010 11:32:04 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WP7]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/uncategorized/the-cleansing-process</guid>
		<description><![CDATA[I spend a large proportion of my time collaborating with UI designers and UI interaction designers where we work closely together to produce interactive UI’s for customers. As someone who is a novice when it comes to Adobe Illustrator and Photoshop I am very reliant on the import functionality in Blend. In this post I [...]]]></description>
			<content:encoded><![CDATA[<p>I spend a large proportion of my time collaborating with UI designers and UI interaction designers where we work closely together to produce interactive UI’s for customers. As someone who is a novice when it comes to Adobe Illustrator and Photoshop I am very reliant on the import functionality in Blend. In this post I want to talk about a simple process that we have adopted to help with bringing those assets from AI and PS in our Xaml based projects.</p>
<p>Before the import features in Blend appeared we used the cool plug-in from Mike Swanson which would allow us to convert vector art work in Xaml. This was incredibility useful and mean that we reduce the time it took to convert these assets into Xaml and then modifying the Xaml in Kaxaml or in Blend. The process worked for us and we continued down this path until the import features in Blend improved and are now at a state where we can easily use the import functionality in Blend to convert these assets even easier.</p>
<p>But, that is not where the story ends, if you have tried out the import process on complex AI or PS visuals then you will have found that when Blend performs the import it positions each layer into a Canvas and will also import any images into the project as well. All in all this is cool however not so much when you have an existing project where you are happy with the code architecture and the folder structure of your application. And, this is what I want to dig into in this post is how to use the import functionality to your advantage.</p>
<p>Where do we start, ok so lets imagine that you have a project which you have setup or a developer on the team has created, its nicely structured and potentially uses MVVM or even a MVVM framework like MVVM Light. We also have a bunch of great looking designs that we need to convert into Xaml assets. We have a couple of options available at this point; we can import directly into the main solution or we can create a separate project a scratch project where we can import into. Admittedly at first I started out by importing directly into the main solution however this became a headache as the solution becomes polluted, by this I mean that when we do the import Blend will create a new folder in our project to hold the images that are referenced in the AI file however we are more than likely have an images folder in the project where all our images live. And for me this is where the management headache begins as we have to work out which images we want to keep and the ones we want to remove, and we also have to then move these images to the right folder and change the references to these images from the Xaml. All in all not too difficult when we break them down but on a large import this can become rather sticky very quickly.</p>
<p>Because of these issues what I have found is that importing into a scratch project is a smoother process for creating your Xaml assets and managing what images you want to keep. So the process goes something like this.</p>
<p>Create a scratch project and setup the folder structure for your Resource Dictionaries and images to mirror the same structure in the main project. Then import you AI or PS file into this project.</p>
<p>Next start to clean up your imported Xaml, the majority of the time you will want to ungroup the visual elements from their containing canvas as the visual elements will have been relatively positioned to mirror the layout defined in AI or PS. You will also find that the designer will have used a number of different layers to create the final appearance of an element. For example the designer may have used 4 different layers in order to create the colour of an element. In these cases my approach is to use the colour picker in Blend to find out what the colour is of the topmost layer, create this colour as a resource in your Resource Dictionary and then remove all the underlying layers until your left with the topmost then apply your newly created colour resource so that the visual element looks like the original. We could leave the visual elements as is however there are performance issues that we may encounter when doing this, in that if you have a list and you are planning on using this visual a number of times then those hidden layers are going to be present in the visual tree which means that the framework will render these and will have an impact on the performance of the application.</p>
<p>Other items to look out for are drop shadows on elements, when performing the import the drop shadows will be translated in a png images. In the majority of cases removing these images and replacing them with a drop shadow effect is the best mechanism, however there are some cases where the png works better. These situations are related to interaction design and occur when you are either; animating the visual elements on screen from one position to another; or you animating the drop shadow effect itself; in these circumstances then leaving the png is desirable and you may also consider using the EnableGPUAcceleration param at the plugin level along with setting the Bitmap Caching mode on your Xaml element.</p>
<p>By this stage you should now have cleansed your import and are ready to start styling and templating the imported visual elements into controls. There are two options available to you at this stage and they are related to your experience and confidence around the templating of the controls. </p>
<p>The first option is to group up the different visual layers that you want to make into the control, the majority of the time grouping them into a Grid or a&#160; Canvas will work for you. From here you can then right click on the layout panel that you created and select “Make into Control” option where you can select from the popup dialog the control that you want to create a style for. From here you can start to assign the visual elements to the parts associated with that template.</p>
<p>The second option is to drag onto the art board the control that you want to style and template and size the control to be the same as the visual elements. Right click on the control and select the “Create a Copy” sub menu option located under “Edit Template” option. This will then provide you with a default template which you can then start to modify so that it takes on the appearance of the visual.</p>
<p>The first option works well if you have intermit knowledge of the template you are creating, it can also work well when you know that you are creating styles and templates for controls which are of a fixed height and width. However, if this is not the case then the second option is a preferred route.</p>
<p>The styles, templates, colour and brush resources that you are using need to be added into the correct Resource Dictionaries. By following this approach you can then pick up the visual elements and merge them into your main solution along with the modifications to the Resource Dictionaries and moving any images that you are using into your images folder.</p>
<p>I hope this insight helps both designers who are creating assets using Adobe products to think about some best practices on how you construct your designs and for the Blend folks this should help with cleaning up the imported Xaml.</p>
<p>As always please let me know your thoughts and also what you have found works best for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/uncategorized/the-cleansing-process/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PathListBox Adventures &#8211; radial layout</title>
		<link>http://blogs.xamlninja.com/silverlight/pathlistbox-adventures-radial-layout</link>
		<comments>http://blogs.xamlninja.com/silverlight/pathlistbox-adventures-radial-layout#comments</comments>
		<pubDate>Mon, 29 Mar 2010 11:13:45 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[PathListBox]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=224</guid>
		<description><![CDATA[The PathListBox ROCKS, if you have not heard of this control before then checkout Christians blog for more details and also his session at mix 10. The PathListBox solves some of the tricky issues related to creating custom panels for a ListBox or ItemsControl. Previously when we need custom layout of visual elements inside of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/RadialPanel.png" rel="shadowbox[sbpost-224];player=img;" target="_blank"><img style="margin: 5px auto; display: block; float: none; border-width: 0px;" title="RadialPanel" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/RadialPanel_thumb.png" border="0" alt="RadialPanel" width="632" height="484" /></a></p>
<p>The PathListBox ROCKS, if you have not heard of this control before then checkout <a href="http://electricbeach.org/" target="_blank">Christians</a> blog for more details and also his session at mix 10. The PathListBox solves some of the tricky issues related to creating custom panels for a ListBox or ItemsControl. Previously when we need custom layout of visual elements inside of these controls we would typically create a custom Panel and crank C# code and some positioning logic to layout the elements as we needed. However, with the introduction of the PathListBox we nolonger have to resort to building a panel and thus lowers the barrier to entry for designers who want to create custom layouts without having to be reliant on a developer to build the panel.</p>
<p>To get going with the PathListBox I wanted to create an simple Silverlight app which pulled back some results from digg, this is something which I have done in the past to illustrate the basics of MVVM in my session from PDC. While on the topic of MVVM its great to see that we now have an MVVM template inside of Blend that we can use. In this post I am not going to talk about the MVVM templates as I have only started out with them and so to give a comparison would not be justifiable at this stage, but I will posting an article when I have it straighten out in my head.</p>
<p>So for this first adventure I created a new MVVM Silverlight application and added a Model and a Service folder. As we already have the code for the digg service and the model created <em>I copied these classes and moved them into their respective folders in the project. Open up the VM that has been added into the project and we can see that it implements INPC. The other thing to notice is that the constructor in parameter less, which is unlike my VM’s where I would normally inject an interface. So for the purposes of this example i am going to new up the interface inside of the constructor.</em></p>
<p>Ok so there are 3 steps that we need to perform in order to recreate the radial panel visual layout that is illustrated above. First we need to create our path on the design surface and then add the PathListBox to the design surface and associate the path with the PathListBox. As with a regular ItemsControl or ListBox we need to bind it to a list of items which in this case is our collection of FeedItems. Blend 4 Beta does quite alot of work for free, you will notice it has created the DataTemplate, ItemContainerStyle and ItemPanelTemplate which is rather nice. So here we start our 3 Steps and each step is associated with the templates and style.</p>
<p>First select the DataTemplate of the PathListBox either from the crumb bar or from right clicking in the objects panel. What we need to do here is add a ChangePropertyAction which fires when we LeftMouseButtonDown on to the DataTemplate so that we can set a flag on the data bound object so that it gets removed from the current list and added to second list. Once we have added this we need to change the RotateTransform on the StackPanel to 90.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxDatatemplateChangePropertyAction.png" rel="shadowbox[sbpost-224];player=img;"><img style="margin: 5px; display: inline; float: none; border-width: 0px;" title="PathListBoxDatatemplateChangePropertyAction" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxDatatemplateChangePropertyAction_thumb.png" border="0" alt="PathListBoxDatatemplateChangePropertyAction" width="644" height="476" /></a></p>
<p>Navigate back to the PathListBox and this time we want to edit the orientation on the items on the path so that they are OrientToPath and check the Wrap Items checkbox.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxSettings.png" rel="shadowbox[sbpost-224];player=img;"><img style="display: inline; border-width: 0px;" title="PathListBoxSettings" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxSettings_thumb.png" border="0" alt="PathListBoxSettings" width="584" height="484" /></a></p>
<p>The second step is to move into our ItemContainerStyle for the PathListBox and change the VSM states so that we have a nice transition for the items when they are loaded and unloaded. With the release of Blend 4 Beta a new set of states have been added to the ListBoxItem. PathListBoxItem subclasses ListBoxItem and so we have the ability to modify the transitions for the BeforeLoaded and AfterLoaded states. For these I</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxStyleLayoutStates.png" rel="shadowbox[sbpost-224];player=img;"><img style="margin: 5px; display: inline; border-width: 0px;" title="PathListBoxStyleLayoutStates" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxStyleLayoutStates_thumb.png" border="0" alt="PathListBoxStyleLayoutStates" width="440" height="154" align="left" /></a></p>
<p>simply changed the Opacity on the root element so that we can have a simple fade in type transition. Next we need to change the length of the transition in this case to 0.3 seconds, and change the easing function to your desired choice. The other changes I made here was to enable the Fluid Layout and turned on the design time layout transitions so that you can see your transitions during design time. Navigate back to the PathListBox.</p>
<p>The final piece to the puzzle is to change the ItemPanelTemplate. Edit the template either via the assets panel or the crumb bar. Here we are looking to add  the FluidMoveBehavior on to our PathPanel which will be responsible for providing the animation effect for moving items between the two PathListBox’s.</p>
<p><a href="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxItemsPanelTemplateFluidMoveBehavior.png" rel="shadowbox[sbpost-224];player=img;"><img style="margin: 5px auto; display: block; float: none; border-width: 0px;" title="PathListBoxItemsPanelTemplateFluidMoveBehavior" src="http://blogs.xamlninja.com/wp-content/uploads/2010/03/PathListBoxItemsPanelTemplateFluidMoveBehavior_thumb.png" border="0" alt="PathListBoxItemsPanelTemplateFluidMoveBehavior" width="644" height="446" /></a> The important things to note here include; we have selected the Children option from the AppliesTo dropdown as we want this particular FluidMoveBehavior to effect all the items in the ListBox; I changed the duration and also the easing functions that I wanted to use; I also selected the DataContext option from the Tag dropdown as I want to capture the data object associated with the item that is being animated. Navigate back to the PathListBox……</p>
<p>And we are done.</p>
<p>3 simple steps for you to add a radial panel layout into your project.</p>
<ol>
<li>Change the data template so that it can handle a user interaction</li>
<li>Change the ItemContainerStyle BeforeLoaded and AfterLoaded States</li>
<li>Change the ItemPanelTemplate by adding in the FluidMoveBehavior</li>
</ol>
<p>We also used ChangePropertyAction to manipulate the data in our collections exposed by the VM, and  we  used the FluidMoveBehavior to animate selected items from one PathListBox to another. The ability to do this without having to write any C# is a great step forwards, it does have some consequences but the advantages from my prospective outweigh the disadvantages.</p>
<p>The next thing that I want to do is animate each individual PathListBoxItem depending on where they are on the Path associated with the PathListBox.</p>
<p>All the code for this example you can find on my SkyDrive Folder.</p>
<p>&lt;iframe title =&#8221;Preview&#8221; scrolling=&#8221;no&#8221; marginheight=&#8221;0&#8243; marginwidth=&#8221;0&#8243; frameborder=&#8221;0&#8243; style=&#8221;width:98px;height:115px;padding:0;background-color:#fcfcfc;&#8221; src=&#8221;http://cid-118ee1873690fc1d.skydrive.live.com/embedicon.aspx/Silverlight4/MvvmApplication3.zip&#8221;&gt;&lt;/iframe&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/pathlistbox-adventures-radial-layout/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Resource Dictionaries</title>
		<link>http://blogs.xamlninja.com/silverlight/resource-dictionaries</link>
		<comments>http://blogs.xamlninja.com/silverlight/resource-dictionaries#comments</comments>
		<pubDate>Tue, 23 Feb 2010 11:46:08 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=156</guid>
		<description><![CDATA[In this post I thought that it would be interesting to share some of my thoughts that I have been having recently around Resource Dictionaries (RD) and how they are structured. It is very easy to just put everything into your generic.Xaml or even into your app.Xaml files and let the designer run away with [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I thought that it would be interesting to share some of my thoughts that I have been having recently around Resource Dictionaries (RD) and how they are structured. It is very easy to just put everything into your generic.Xaml or even into your app.Xaml files and let the designer run away with implementing their designs, but this is not too say that its the best way to roll.</p>
<p>From a developer prospective these files can become large very quickly and the result is a complete management headache when it comes to maintaining the styles, control and data templates. Its is also rather easy&#160; to allow this to happen as its in the Xaml and its what the designer produces, in effect its someone else&#8217;s responsibility. What is rather interesting and confusing at the same time is that Blend actually works very well when it comes to dealing with resources that are all in one file and it provides the designer with an easy way manage styles and templates. The other interesting thing about RD is that its actually at the heart of the Designer and Developer collaboration, its one of the areas where these two worlds collide. Therefore one of the ways in which we can help improve the workflow is to have a better understanding of RD and create some guidelines on how to best go about structuring them.</p>
<p>Unfortunately, even though RD are one of the core parts that make up the presentation layer there is very little information on best practices on how we should be doing this and why its important to get it right in order from which to have a good platform to move off from. Structuring RD in the wrong way can have rather serious performance problems.</p>
<p>There is a great article on the WPF Disciples pages providing very good advice on how to structure your RD and naming conventions, but I want to attempt to take it a little further. There are a number of different scenarios that I have come across and I am sure that there will be more along the way.&#160; These include; a POC application where this is built quickly and iteratively and requires a compelling UI but there is a high potential the application will not make it into production; themeable applications where a number of different themes can be applied to change the look and feel; and also applications that leverage 3rd party controls which have their own and sometimes rather interesting ways of how they are styled and templated. Each scenario is different but can be solved in the same way by using well structured RD to produce a clean, performant and easy to maintain application.</p>
<p>Ok, so how can we achieve a better structuring of the RD, help improve collaboration and provide a basic pattern and best practices in order to satisfy the different scenarios outlined above ?</p>
<p>Putting your RD in a separate project is the first thing to do, there are a number of advantages in doing this; but primarily this is about separation of concerns to help with workflow; and it helps to provide a blue print of a theme that can be reused over time. </p>
<p>In addition to the guidelines put forwards from the WPF list I am also going to add some more into the mix.</p>
<p>Suggested WPF Disciples Resources :-</p>
<p>BrushResources – solid brushes, linear gradient brushes and drawing brushes</p>
<p>ConverterResources &#8211; allows us to reference any of the converters by merging our resource dictionary with this file, rather than re-declaring our converters every time.</p>
<p>ImageResources &#8211; as above, allows us to declare an ImageSource once and reference it from anywhere.&#160; </p>
<p>TextResources -styles applied to textual elements (Hyperlinks, TextBlocks, etc.)</p>
<p>Additional Resources:-</p>
<p>Colours – for simple colours used as a swash for branding of clients colour palette.</p>
<p>DataTemplates – holds all the Data Templates used in the application.</p>
<p>Storyboards – holds all the Storyboard animations.</p>
<p>VectorGraphics – holds all the vectors graphics</p>
<p>CustomControls – holds styles and templates for those custom lookless controls</p>
<p>CommonControls- holds styles and templates for those common controls</p>
<p>Now the above list is not an exhaustive one and there is a high potential that this may change in the future but for now these provide a good platform from which to start. There are a number of ways in which you can slice and dice the RD used in your application some of which I will talk about shortly, but in general its best to think about the RD as a whole. The reason for this is that its best to see the Xaml assets as what constitutes your design and interaction of the UI that you are projecting onto the view for the user to experience. Therefore a change in the template or style means a&#160; complete new design. By thinking about them in a more holistic view as a the sum of all parts.</p>
<p>Therefore by splitting up the styles, templates etc into different high level RD categories provides the capabilities for the designers to work in an independent way and not have the constraints of working in the same project as the developers. The majority of times you will want to split out the RD into a separate project, and provide an area where they can create and design controls and elements. It also means that as they are working in a separate project they are completely separated from the developers but they are both working in the same solution.</p>
<p>What are those other views of RD that I mentioned earlier. Another potential way of looking at splitting up the RD is to break out the control templates and styles and place those into separate files. This will provide the ability to change the colours, font types etc and leave the control templates alone, which is great for those situations where you want to restyle the application and want to retain the layout of the controls. However, there are some problems with this approach; making significant changes to the style of controls will almost certainly mean that you will have to change the layout of the control, or building a custom control to handle the different styles; support in Blend for this type of structure is sub optimal in that it becomes more difficult to navigate and manage the styles and templates.</p>
<p>So why is it important to structure the RD in this way ? Why can they live all in the same Generic.Xaml file ? Is it the developer or the designer who owns the files ? How does this make my application more themeable ?</p>
<p>So those are a few of the questions which I have been asked about recently from both designers and developers, and they are all good questions and ones which i have also been thinking about hence my solution attempts to tackle these questions and provide a simpler implementation of how to use RD in your app.</p>
<p>One of the main problems with coming up with a good structure is the lack of guidance that is actually out there, plenty of high level information around some structure and naming conventions but no real information on the details. Rather frustratingly although we have gone head first into solving and building frameworks that address MVVM and come up with some notable solutions. It does feels like we have neglected an important area of the presentation layer.</p>
<p>What is rather interesting is how differently developers and designers perceive RD and this comes out in how they implement them in the app. </p>
<p>Developer : As a developer it is a natural and in the interest of best practices to split out each individual control so that each control is sat in its own RD. </p>
<p>Designer: As a designer its natural to think of all the controls at a higher level so that at set of individual controls contribute to the overall design of the app.</p>
<p>So as you can see neither side is right or wrong its their interpretation of RD which differs and this is natural as the different roles have different views and priorities on what is required to build the User Experience. What is interesting as well is that these opinions are skewed by the tools that they use and how they interpret and solve problems. The developer is very much focused on detail and implementation, mean while the designer is more interested in the higher level and the total experience of their design. </p>
<p>Therefore a combination of both these views seems to feel right where we split up the RD into a higher level categorisation with good naming conventions. This approach meets both parties needs and is Blendable allowing the designer to work in an environment which has a reduced reliance on the developer world and vice versa.</p>
<p>So I am hoping this that has made you think a little more about RD. In the next post I am going to talk more about how to implement the RD in your application and drill into the performance issues related to implementing RD and some sample code to help with guidance.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/resource-dictionaries/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PDC09 &#8211; Meet the Griffs Code drop</title>
		<link>http://blogs.xamlninja.com/silverlight/pdc09-meet-the-griffs-code-drop</link>
		<comments>http://blogs.xamlninja.com/silverlight/pdc09-meet-the-griffs-code-drop#comments</comments>
		<pubDate>Thu, 19 Nov 2009 18:58:35 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Ninject]]></category>
		<category><![CDATA[PDC09]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=132</guid>
		<description><![CDATA[Ian and myself really enjoyed presenting our pre conference session  “Getting the most out of Silverlight” and we both hope that you enjoyed the sessions. The slide decks will be posted at some point by the event team and I will update the post when this happens so that you can get copies of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.interact-sw.co.uk/iangblog/" target="_blank">Ian</a> and myself really enjoyed presenting our pre conference session  “Getting the most out of Silverlight” and we both hope that you enjoyed the sessions. The slide decks will be posted at some point by the event team and I will update the post when this happens so that you can get copies of the decks.</p>
<p>As promised I have stashed all the final code examples up on my skydrive folder so that you can download and play with the samples. As we ran out of time in the last session what I will do in the next week or so is to record a Camtasia session and capture what I unfortunately did not get time to go over during the session.</p>
<p>I have named the zip files as intuitively as possible so these line up with the title of the session.</p>
<p>What I also wanted to briefly mention is that in the MEF and Ninject demos you will see that I am using Commands from the Silverlight Extensions project on <a href="http://www.codeplex.com/SLExtensions" target="_blank">CodePlex</a>. The command pattern that is used here is a standard command pattern common to WPF. In the current release there is no support for Commands so what you will see included in the projects are the Command classes that I need in order to harness the power of Commands.</p>
<p>In a previous life I wrote a <a href="http://consultingblogs.emc.com/richardgriffin/archive/2007/02/23/WPF-Commands-a-scenic-tour-part-I.aspx" target="_blank">post</a> on WPF commands that you may want to take a look at if you are not familiar to the Command pattern used in WPF and how it helps to separate out UI logic into you View Model and helps increase the testability of your code that responds to the behaviours in your application. The refactor that I did here was to remove the click event handler on the button and replace this with a command. There are 3 steps for refactoring out the event handler.</p>
<p>First we need to create a commands.cs file and create a Commands class which will hold all our commands associated with our view model. In essence we are going to be providing a list of possible actions that the View Model can perform in relation to the view. Once we have created the class we need to define our commands that we want which in our demo is called RefreshFeedItems then we need to add in public mechanism so that we can invoke the command from the view so that it can be wired up to a button.</p>
<pre class="brush: csharp">

using StandardViewModel.SLExtensions.Input;

public class Commands
{
      private static readonly Command refreshFeeds = new Command(RefreshFeedItems);

      public static Command RefreshFeedItems

      { get { return refreshFeeds; } } }
</pre>
<p>Now that we have defined the command that we want to fire we need to do the second part which is to wire up the command in the Xaml of the view.</p>
<pre class="brush: xml">
     Input:CommandService.Command=RefreshFeedItems

     &lt;Button Content=Refresh
                    Grid.Column=2
                    Margin=&quot;3,3,3,3&quot;
                    IsEnabled=&quot;{Binding IsRefreshEnabled}&quot;
                    Input:CommandService.Command=&quot;RefreshFeedItems&quot; /&gt;
</pre>
<p>We can now remove the click handler code behind of the view.</p>
<p>The finally part is to implement the CanExecute and Executed code in the ViewModel, so move into the Constructor of the ViewModel and here wire up the commands.</p>
<pre class="brush: csharp">
       Commands.RefreshFeedItems.CanExecute += (sender, args) args.CanExecute = true;
       Commands.RefreshFeedItems.Executed += delegate(object sender, ExecutedEventArgs args)
         {
                        Refresh();
         };
</pre>
<p>And we are done. Enjoy. One thing to note is that there are other types of commands, <a href="http://joshsmithonwpf.wordpress.com/2008/11/17/emulating-icommandsource-in-silverlight-2/" target="_blank">RelayCommand</a> and <a href="http://www.mokosh.co.uk/post/Prism-2-WPF-and-Silverlight-Commands.aspx" target="_blank">DelegateCommand</a> which are also very cool black belt ninja moves for dealing with separation when building your MVVM apps</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/pdc09-meet-the-griffs-code-drop/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MVVM, design time data, and Blendability</title>
		<link>http://blogs.xamlninja.com/silverlight/mvvm-design-time-data-and-blendability</link>
		<comments>http://blogs.xamlninja.com/silverlight/mvvm-design-time-data-and-blendability#comments</comments>
		<pubDate>Fri, 02 Oct 2009 08:44:15 +0000</pubDate>
		<dc:creator>rich</dc:creator>
				<category><![CDATA[Blend]]></category>
		<category><![CDATA[MVVM]]></category>
		<category><![CDATA[Ninject]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Xaml]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://blogs.xamlninja.com/?p=34</guid>
		<description><![CDATA[With the introduction of design time data support in Blend I thought that I would try and take advantage of using design time data and MVVM. For a while now I have been using Ninject, with a Service Locator Pattern to provide the ability to build WPF and Silverlight apps in an MVVM pattern where [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blogs.xamlninja.com/wp-content/uploads/2009/10/Designtimedataprojectstructure1.PNG" alt="Designtimedataprojectstructure" title="Designtimedataprojectstructure" width="444" height="450" class="alignleft size-full wp-image-84" />With the introduction of design time data support in Blend I thought that I would try and take advantage of using design time data and MVVM. For a while now I have been using Ninject, with a Service Locator Pattern to provide the ability to build WPF and Silverlight apps in an MVVM pattern where I prefer to use a View first mechanism. There are a number of benefits from using this approach, one of the ones that we are good to drill to in this post is around Blendability of the controls that developers create. Prior to me using Ninject I would have a heavy reliance on the DesignerProperties IsInDesignMode call to check to see if the control was being render in Blend, as i would normally have to do something to stop the control from crashing and allow myself and the designer to use Blend in order for us to Style and Template the controls we created.</p>
<p>What we are going to cover here is the journey which i went on when adding support for design time data to my project, I really like it as the refactoring from the standard inbuilt mechanism in Blend to the final output is a nice series of steps that feel good.<br />
<a href="http://blogs.xamlninja.com/wp-content/uploads/2009/10/Designtimedata.png" rel="shadowbox[sbpost-34];player=img;"><img style="border-right-width: 0px; margin: 10px 5px 10px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Designtimedata" src="http://blogs.xamlninja.com/wp-content/uploads/2009/10/Designtimedata_thumb.png" border="0" alt="Designtimedata" width="395" height="276" align="right" /></a></p>
<p>The screen shot on the right shows the simple looking UI displaying contextual data in Blend allowing the designer to see how the control will look. I think providing the ability for your application to look exactly the same at design time as at run time is going to mean that you can produce better looking applications quicker as the designer is design the screens in the context of the data.</p>
<p>When first adding the design time data to your project Blend takes over control and this means that you need to use Blend to shape your design time data classes to match your data types used in the system. So if we were building a throw away prototype then I would agree this is the best way forwards, but when you are moving from prototype to production this does not really work. On of the reasons behind the research for this post is around the transition from prototype to production and even from sketch to prototype, once we have sign off from the client on a number of ideas and we want to start to build these out then there is a high potential one will become production quality and because of this its good to have the right architecture in place, so reshaping to MVVM early on will almost certainly cost your client less.</p>
<p>The Xaml below is what i put together to represent the shape of data that was in the mock classes. Blend then hooks this data up to the design time data context for you.</p>
<p>Xaml data for shopping cart</p>
<pre class="brush: xml">
&lt;local:ShoppingCartViewModel xmlns:local=&quot;clr-namespace:DesignDataSample;assembly=DesignDataSample&quot;&gt;
    &lt;local:ShoppingCartViewModel.ShoppingCart xmlns:local=&quot;clr-namespace:DesignDataSample;assembly=DesignDataSample&quot;&gt;
        &lt;local:ShoppingCart&gt;
            &lt;local:ShoppingCart.Items&gt;
                &lt;local:ShoppingCartItem ItemName=&quot;Book Name 1&quot;
                                        ItemDescription=&quot;A very nice book!&quot;
                                        ItemImage=&quot;MySampleDataImages/Tree.jpg&quot; /&gt;
                &lt;local:ShoppingCartItem ItemName=&quot;Book Name 2&quot;
                                        ItemDescription=&quot;A very nice book!&quot;
                                        ItemImage=&quot;MySampleDataImages/Tree.jpg&quot; /&gt;
                &lt;local:ShoppingCartItem ItemName=&quot;Book Name 3&quot;
                                        ItemDescription=&quot;A very nice book!&quot;
                                        ItemImage=&quot;MySampleDataImages/Tree.jpg&quot; /&gt;
                &lt;local:ShoppingCartItem ItemName=&quot;Book Name 4&quot;
                                        ItemDescription=&quot;A very nice book!&quot;
                                        ItemImage=&quot;MySampleDataImages/Tree.jpg&quot; /&gt;
            &lt;/local:ShoppingCart.Items&gt;
        &lt;/local:ShoppingCart&gt;
    &lt;/local:ShoppingCartViewModel.ShoppingCart&gt;
&lt;/local:ShoppingCartViewModel&gt;
</pre>
<p>When the design time data shape matches your real data shape you can then go ahead and use the new d:DataContext Dependency Property and bind your design time data to this property.</p>
<p>Xaml Source code for the control</p>
<pre class="brush: xml">
&lt;UserControl
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
             mc:Ignorable=&quot;d&quot;
             x:Class=&quot;DesignDataSample.ShoppingCartView&quot;
             d:DataContext=&quot;{d:DesignData Source=ShoppingCartSampleData.xaml}&quot;
             DataContext=&quot;{Binding Path=ShoppingCartViewModel, Source={StaticResource serviceLocator}}&quot;
             Height=&quot;347&quot;
             Width=&quot;494&quot;&gt;
</pre>
<p>Nothing too tricky there, the new design time data context is the key to making all this happen, it also means that you can bind any sort of data you want to the design time data context to provide contextual data in Blend during design time. It was at this point that i started to think about how we can really bend the design time data features. My initial refactor was not a great result in that I ended up with 2 sets of mock data; one set of data would be used by the designers in Blend; and the second set of data would be used by the unit test, Not nice, management nightmare to ensure that both data sets are keep in sync.</p>
<p>So the goal was to provide design time data which was the same data used by the unit tests, meaning that we only have one data set to maintain and manage, allowing us to leverage the powerful features of design time data in Blend and also keeping our unit tests looking sweet, pleasing both the designers and the developers on the team.</p>
<p>In order to do this I needed to restructure the existing shape of my data classes that I use in my mock service layer classes, first I needed to change the OnCompleted method to be a virtual implementation and also the method which retrieves the data. This simple change means that we can now provide two mock services that can be injected in.</p>
<p>Refactored mock service class with new virtual methods</p>
<pre class="brush: csharp">
    using System;
    using System.Collections.ObjectModel;

    public class MockShoppingCartService : IShoppingCartService
    {
        public event GetShoppingCartCompletedHandler GetShoppingCartCompleted;

        public bool LoginToShoppingCart(string username, string password)
        {
            throw new System.NotImplementedException();
        }

        public virtual void RetrieveShoppingCart()
        {
            this.OnGetShoppingCartCompleted(null, MockShoppingCartData.CreateShoppingCartRuntime());
        }

        protected virtual void OnGetShoppingCartCompleted(Exception error, ShoppingCart result)
        {
            if (this.GetShoppingCartCompleted != null)
            {
                this.GetShoppingCartCompleted(new GetShoppingCartCompletedEventArgs(error, result));
            }
        }
    }
</pre>
<p>The new mock service class which is used specifically for working with Blend</p>
<pre class="brush: csharp">
namespace DesignDataSample.Mocks
{
    public class MockShoppingCartServiceDesignData : MockShoppingCartService
    {
        public override void RetrieveShoppingCart()
        {
            this.OnGetShoppingCartCompleted(null, MockShoppingCartData.CreateShoppingCartDesigntime());
        }
    }
}
</pre>
<p>How we can use ninject to inject the service we want to use, design time data, mock or real.</p>
<pre class="brush: csharp">
this.Bind&lt;IShoppingCartService&gt;().To&lt;MockShoppingCartService&gt;().OnlyIf(c =&gt; isBrowser);
this.Bind&lt;IShoppingCartService&gt;().To&lt;MockShoppingCartServiceDesignData&gt;().OnlyIf(c =&gt; isBlend);
this.Bind&lt;IShoppingCartService&gt;().To&lt;ShoppingCartService&gt;().OnlyIf(c =&gt; isBrowser);
this.Bind&lt;ShoppingCartViewModel&gt;().ToSelf();
</pre>
<p>Xaml code for how we leverage the data context and the new design time data context for providing contextual data.</p>
<pre class="brush: xml">
&lt;UserControl
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
             xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
             xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
             xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
             mc:Ignorable=&quot;d&quot;
             x:Class=&quot;DesignDataSample.ShoppingCartView&quot;
             d:DataContext=&quot;{Binding Path=ShoppingCartViewModel, Source={StaticResource serviceLocator}}&quot;
             DataContext=&quot;{Binding Path=ShoppingCartViewModel, Source={StaticResource serviceLocator}}&quot; Height=&quot;347&quot; Width=&quot;494&quot;&gt;
&lt;!--d:DataContext=&quot;{d:DesignData Source=ShoppingCartSampleData.xaml}&quot;--&gt;
    &lt;UserControl.Resources&gt;
        &lt;DataTemplate x:Key=&quot;ShoppingCartItemTemplate&quot;&gt;
            &lt;Grid Height=&quot;50&quot;&gt;
                &lt;Grid.ColumnDefinitions&gt;
                    &lt;ColumnDefinition Width=&quot;50&quot; /&gt;
                    &lt;ColumnDefinition Width=&quot;*&quot; /&gt;
                &lt;/Grid.ColumnDefinitions&gt;
                &lt;Grid.RowDefinitions&gt;
                    &lt;RowDefinition Height=&quot;*&quot; /&gt;
                    &lt;RowDefinition Height=&quot;*&quot; /&gt;
                &lt;/Grid.RowDefinitions&gt;

                &lt;Image Source=&quot;{Binding ItemImage}&quot;
                       Grid.RowSpan=&quot;2&quot; /&gt;
                &lt;TextBlock Text=&quot;{Binding ItemName}&quot;
                           Grid.Column=&quot;1&quot;
                           Margin=&quot;4,0,0,0&quot; /&gt;
                &lt;TextBlock Text=&quot;{Binding ItemDescription}&quot;
                           Grid.Column=&quot;1&quot;
                           Grid.Row=&quot;1&quot;
                           Margin=&quot;4,0,0,0&quot; /&gt;
            &lt;/Grid&gt;
        &lt;/DataTemplate&gt;
    &lt;/UserControl.Resources&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot;
          Background=&quot;#FFB2B2B2&quot;&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition /&gt;
            &lt;ColumnDefinition Width=&quot;129&quot; /&gt;
            &lt;ColumnDefinition Width=&quot;121&quot; /&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition /&gt;
            &lt;RowDefinition Height=&quot;50&quot; /&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;ListBox Margin=&quot;8,8,8,26&quot;
                 Grid.ColumnSpan=&quot;3&quot;
                 ItemsSource=&quot;{Binding Mode=OneWay, Path=ShoppingCart.Items}&quot;
                 ItemTemplate=&quot;{StaticResource ShoppingCartItemTemplate}&quot; /&gt;
        &lt;TextBlock Grid.Row=&quot;1&quot;
                   Text=&quot;Total Items:&quot;
                   TextWrapping=&quot;Wrap&quot;
                   Grid.Column=&quot;1&quot; /&gt;
        &lt;TextBlock Grid.Column=&quot;2&quot;
                   Grid.Row=&quot;1&quot;
                   Text=&quot;{Binding ShoppingCart.Items.Count}&quot;
                   TextWrapping=&quot;Wrap&quot; /&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;</pre>
<p> </p>
<p>So I hope that this article has opened your eyes to how useful design time data can be to enhance the Blendability of the controls which you produce both lookless and user. In the majority of cases designers that you are working with really like that they can view the control at deign time how it will appear when running in your application and populated with data.  When implementing the MVVM pattern in you application incorporating support for design time data is also possible and provides you with the ultimate Xaml Ninja experience.</p>
<p>You can download the source from my Skydrive.</p>
<p><iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-118ee1873690fc1d.skydrive.live.com/embedicon.aspx/Silverlight3/DesignData/DesignDataSample.zip"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.xamlninja.com/silverlight/mvvm-design-time-data-and-blendability/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

