<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Hibernating Rhinos</title><link>http://blog.hibernatingrhinos.com/</link><description>Hibernating Rhinos</description><copyright>Hibernating Rhinos (c) 2009 - 2011 (c) 2012</copyright><ttl>60</ttl><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/HibernatingRhinos" /><feedburner:info uri="hibernatingrhinos" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>Fade-Trimming TextBlocks in Silverlight and WPF</title><description>&lt;blockquote&gt; &lt;blockquote&gt; &lt;p&gt;This is a guest post by &lt;a href="http://blog.functionalfun.net/"&gt;Samuel Jack&lt;/a&gt;, who had done a lot of work on the new UI for RavenFS.&lt;/p&gt;&lt;/blockquote&gt;&lt;/blockquote&gt; &lt;p&gt;Using ellipsis is &lt;em&gt;so&lt;/em&gt; last year. When did you last see the cool HTML 5 kids writing … when they couldn’t fit all their text in a column? They’ve got this fancy new feature, powered by CSS3, where text that doesn’t quite fit simply fades out as it reaches the edge of the text block. Like this (with thanks to the &lt;a href="http://quickui.org/catalog/Fader/"&gt;QuickUI Catalog&lt;/a&gt;)&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/476f7ab3e3ba_C64A/image_2.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/476f7ab3e3ba_C64A/image_thumb.png" width="240" height="52"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Subtle! It looks much prettier, and it means you can fit in an extra three characters of real text instead of the …s.&lt;/p&gt; &lt;p&gt;Silverlight’s future might be uncertain, but I want to show you that it isn’t ready to roll over and die just yet. We can have those fancy fade-trimming effects too!&lt;/p&gt; &lt;p&gt;As part of the work I’m doing on the UI for &lt;a href="http://ayende.com/blog/4828/designing-ravenfs"&gt;RavenFS&lt;/a&gt; I implemented Fade-trimming to make our DataGrids look smarter, and I thought it would be nice to share. So I’ve packaged up all you need it into an easy-to-use class called &lt;a href="https://github.com/samueldjack/FadeTrimming/blob/master/FadeTrimmingDemo.Silverlight/FadeTrimming.cs"&gt;FadeTrimming.cs&lt;/a&gt; which works in Silverlight and WPF, and given you &lt;a href="https://github.com/samueldjack/FadeTrimming"&gt;two demo projects&lt;/a&gt; to show you how to get started.&lt;/p&gt; &lt;h3&gt;How to use it&lt;/h3&gt; &lt;p&gt;Include the &lt;a href="https://github.com/samueldjack/FadeTrimming/blob/master/FadeTrimmingDemo.Silverlight/FadeTrimming.cs"&gt;FadeTrimming.cs&lt;/a&gt; file in your project. Add a namespace reference in the root element of your XAML file like this:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:207a9bff-ece9-4095-a27c-ad0c463843ac" class="wlWriterSmartContent"&gt;&lt;pre style="background-color: white; overflow: auto"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Window &lt;/span&gt;&lt;span style="color: #ff0000"&gt;x:Class&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="FadeTrimmingDemo.Wpf.MainWindow"&lt;/span&gt;&lt;span style="color: #ff0000"&gt;
        xmlns&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;&lt;span style="color: #ff0000"&gt;
        xmlns:x&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; 
        
        xmlns:b&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="clr-namespace:SilverlightEffects"&lt;/span&gt;&lt;span style="color: #ff0000"&gt;
        
        Title&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="MainWindow"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; Height&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="350"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="525"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;p&gt;You can then enable Fade Trimming on individual TextBlocks like this:&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:cdb5e2af-1603-433d-8150-a2b6917e1a2f" class="wlWriterSmartContent"&gt;&lt;pre style="background-color: white; overflow: auto"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBlock &lt;/span&gt;&lt;span style="color: #ff0000"&gt;b:FadeTrimming.IsEnabled&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="True"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBlock&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;p&gt;or using a Style, like this:&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:07bd961b-3f1b-4e2c-8a10-b8ee1960e210" class="wlWriterSmartContent"&gt;&lt;pre style="background-color: #ffffff; overflow: auto"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Style &lt;/span&gt;&lt;span style="color: #ff0000"&gt;x:Key&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Style_TextBlock_FadeTrimming"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; TargetType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="TextBlock"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
    &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;Setter &lt;/span&gt;&lt;span style="color: #ff0000"&gt;Property&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="b:FadeTrimming.IsEnabled"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; Value&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="True"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;Style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;p&gt;If you want to use it in a column of a DataGrid, try this:&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5196f3c7-9ea8-467f-9ede-c27c27c9ae4f" class="wlWriterSmartContent"&gt;&lt;pre style="background-color: #ffffff; overflow: auto"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;sdk:DataGridTemplateColumn &lt;/span&gt;&lt;span style="color: #ff0000"&gt;Header&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Name"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; Width&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="*"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
     &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;sdk:DataGridTemplateColumn.CellTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
         &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
             &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;TextBlock &lt;/span&gt;&lt;span style="color: #ff0000"&gt;Text&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="&lt;/span&gt;&lt;span style="color: #808000"&gt;{Binding Item.Name}&lt;/span&gt;&lt;span style="color: #0000ff"&gt;"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; 
                        b:FadeTrimming.IsEnabled&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="True"&lt;/span&gt;&lt;span style="color: #ff0000"&gt; 
                        b:FadeTrimming.ShowTextInToolTipWhenTrimmed&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="True"&lt;/span&gt;&lt;span style="color: #ff0000"&gt;
                        VerticalAlignment&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="Center"&lt;/span&gt;&lt;span style="color: #ff0000"&gt;
                        Margin&lt;/span&gt;&lt;span style="color: #0000ff"&gt;="4"&lt;/span&gt;&lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
         &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
     &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;sdk:DataGridTemplateColumn.CellTemplate&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;
 &lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000"&gt;sdk:DataGridTemplateColumn&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;p&gt;This last example shows another useful feature. Set &lt;em&gt;b:FadeTrimming.ShowTextInToolTipWhenTrimmed="True",&lt;/em&gt; and when the text is trimmed, the TextBlock will automatically start showing the full text in its tool tip.&lt;/p&gt;
&lt;p&gt;A couple of things to note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If &lt;em&gt;TextBlock.TextWrapper&lt;/em&gt; is set to &lt;em&gt;NoWrap&lt;/em&gt;, then the &lt;em&gt;TextBlock&lt;/em&gt; will be fade-trimmed on the left. Otherwise, when text wrapping is switched on, it will be fade-trimmed at the bottom. 
&lt;li&gt;You’ll probably want to set &lt;em&gt;TextOptions.TextHintingMode=”Animated”&lt;/em&gt;. Otherwise there’s a strange rendering glitch in Silverlight where the font appears darker when it is fade-trimmed. I don’t think my code’s to blame: it seems to happen whenever text is rendered using anything other than a &lt;em&gt;SolidColorBrush&lt;/em&gt;. &lt;em&gt;TextHintingMode&lt;/em&gt; is an inherited property, so you can set it on a root element and it will flow to the children. 
&lt;li&gt;When TextBlocks are used in certain places (e.g. as direct children of Grids, with GridSplitters involved) they don’t seem to get the events they need to know when to update the Fade Trimming. The solution is to wrap the TextBlock in another element, usually a Border, and then everything works as it should. &lt;/li&gt;&lt;/ul&gt;
&lt;h3&gt;&lt;/h3&gt;
&lt;h3&gt;How it works&lt;/h3&gt;
&lt;p&gt;There are two key ingredients to this fade-trimming trick:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Knowing when and where the TextBlock has been clipped 
&lt;li&gt;Setting the TextBlock’s Foreground brush to a LinearGradientBrush that fades to transparent just before the clip boundary. &lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;Finding out if and how an element has been clipped in Silverlight turns out to be very easy. You just call&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:6afd5c27-d01f-4c3a-a53b-f884423562fc" class="wlWriterSmartContent"&gt;&lt;pre style="background-color: #ffffff; overflow: auto"&gt;&lt;span style="color: #000000"&gt;var layoutClip &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; LayoutInformation.GetLayoutClip(_textBlock);&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;layoutClip&lt;/em&gt; will be null if the element is not clipped. Otherwise its &lt;em&gt;Bounds&lt;/em&gt; property will be set to a rectangle outlining the visible area of the element. &lt;/p&gt;
&lt;h3&gt;Fading at the edges&lt;/h3&gt;
&lt;p&gt;Setting up the TextBlock’s Foreground Brush is slightly more involved. Here’s how we do it for a horizontally clipped TextBlock:&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:9c8ad4c8-9797-4c5a-b168-a7ba0d294bb3" class="wlWriterSmartContent"&gt;&lt;pre style="background-color: #ffffff; overflow: auto"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt;&lt;span style="color: #000000"&gt; LinearGradientBrush GetHorizontalClipBrush(&lt;/span&gt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;&lt;span style="color: #000000"&gt; visibleWidth)
{
    &lt;/span&gt;&lt;span style="color: #0000ff"&gt;return&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; LinearGradientBrush
    {
        &lt;/span&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;span style="color: #008000"&gt; set MappingMode to absolute so that
        &lt;/span&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;span style="color: #008000"&gt; we can specify the EndPoint of the brush in
        &lt;/span&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;span style="color: #008000"&gt; terms of the TextBlock's actual dimensions&lt;/span&gt;&lt;span style="color: #008000"&gt;
&lt;/span&gt;&lt;span style="color: #000000"&gt;        MappingMode &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; BrushMappingMode.Absolute,
        StartPoint &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; Point(&lt;/span&gt;&lt;span style="color: #800080"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;, &lt;/span&gt;&lt;span style="color: #800080"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;),
        EndPoint &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; Point(visibleWidth, &lt;/span&gt;&lt;span style="color: #800080"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;),
        GradientStops &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt;
            {
                &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; GradientStop()
                    {Color &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; _foregroundColor, Offset &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #800080"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;},
                &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; GradientStop()
                    {
                        Color &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; _foregroundColor,
                        &lt;/span&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;span style="color: #008000"&gt; Even though the mapping mode is absolute,
                        &lt;/span&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;span style="color: #008000"&gt; the offset for gradient stops is always relative with
                        &lt;/span&gt;&lt;span style="color: #008000"&gt;//&lt;/span&gt;&lt;span style="color: #008000"&gt; 0 being the start of the brush, and 1 the end of the brush&lt;/span&gt;&lt;span style="color: #008000"&gt;
&lt;/span&gt;&lt;span style="color: #000000"&gt;                        Offset &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; (visibleWidth &lt;/span&gt;&lt;span style="color: #000000"&gt;-&lt;/span&gt;&lt;span style="color: #000000"&gt; FadeWidth)&lt;/span&gt;&lt;span style="color: #000000"&gt;/&lt;/span&gt;&lt;span style="color: #000000"&gt;visibleWidth
                    },
                &lt;/span&gt;&lt;span style="color: #0000ff"&gt;new&lt;/span&gt;&lt;span style="color: #000000"&gt; GradientStop()
                    {
                        Color &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; Color.FromArgb(&lt;/span&gt;&lt;span style="color: #800080"&gt;0&lt;/span&gt;&lt;span style="color: #000000"&gt;, _foregroundColor.R, _foregroundColor.G, _foregroundColor.B),
                        Offset &lt;/span&gt;&lt;span style="color: #000000"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: #800080"&gt;1&lt;/span&gt;&lt;span style="color: #000000"&gt;
                    }
            }
    };
}&lt;/span&gt;&lt;/pre&gt;&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;&lt;/div&gt;
&lt;p&gt;First we create a &lt;em&gt;LinearGradientBrush&lt;/em&gt; and set its &lt;em&gt;MappingMode&lt;/em&gt; to &lt;em&gt;BrushMappingMode.Absolute. &lt;/em&gt;This allows us to set the &lt;em&gt;StartPoint&lt;/em&gt; and &lt;em&gt;EndPoint&lt;/em&gt; in terms of coordinates on the TextBlock itself. We set &lt;em&gt;StartPoint&lt;/em&gt; to the top left corner of the TextBlock, and &lt;em&gt;EndPoint&lt;/em&gt; to the edge of the visible region.&lt;/p&gt;
&lt;p&gt;Then we set three &lt;em&gt;GradientStops&lt;/em&gt;, the first two in the solid foreground color, and the last one, at the edge of the clipping region, completely transparent. One oddity with &lt;em&gt;GradientStops&lt;/em&gt; is that even though the brush mapping mode is &lt;em&gt;Absolute&lt;/em&gt; their values are still relative – but relative to the &lt;em&gt;StartPoint&lt;/em&gt; and &lt;em&gt;EndPoint&lt;/em&gt; of the brush. So &lt;em&gt;Offset&lt;/em&gt; = 0 maps to the &lt;em&gt;StartPoint&lt;/em&gt; of the Brush, and &lt;em&gt;Offset&lt;/em&gt; = 1 maps to the end point of the brush. We want the fade to start a few pixels in from the edge of the visible area, so we set the &lt;em&gt;Offset &lt;/em&gt;of the second &lt;em&gt;GradientStop&lt;/em&gt; to&lt;em&gt; (visibleWidth - FadeWidth)/visibleWidth&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;Other points of interest&lt;/h3&gt;
&lt;p&gt;There are a couple of other points of interest, if you fancy inspecting the code.&lt;/p&gt;
&lt;p&gt;One is that the clipping requirements of the TextBlock can change for many reasons. It could change because the length of the text changing, or because the font size or style changes, or because the size of the text block itself changes (imagine it is in a column of a DataGrid that the user is expanding or contracting). Whenever any of these changes occur, we need to update our special Foreground brush so the gradient fades out at the right point.&lt;/p&gt;
&lt;p&gt;It turns out that we can handle all of these cases just by listening for the SizeChanged event on the TextBlock and of its visual parent. Note that the visual parent is &lt;em&gt;not&lt;/em&gt; the one you obtain by calling TextBlock.Parent. That gets you the logical parent (see &lt;a href="http://msdn.microsoft.com/en-us/library/cc189034(v=vs.95).aspx"&gt;here&lt;/a&gt; to understand the difference). To get the Visual parent you call &lt;em&gt;VisualTreeHelper.GetParent(_textBlock). &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Before I hit on the trick of using the Foreground brush, I tried implementing this using &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacitymask.aspx"&gt;OpacityMasks&lt;/a&gt;. That worked too, but it was horribly slow once you enabled fade-trimming on any significant number of TextBlocks. But that is only to be expected when you remember how OpacityMasks work. An OpacityMask is a Brush from which Silverlight extracts just the Alpha channel. To display an element with an OpacityMask, Silverlight first has to render everything behind the element, then it has to render the element (and each of its children), then finally it has to composite the two pixel-by-pixel, giving each pixel of the element the transparency determined by the corresponding pixel in the OpacityMask brush. And none of that work is &lt;a href="http://msdn.microsoft.com/en-us/library/ee309563(v=vs.95).aspx"&gt;hardware accelerated&lt;/a&gt;. OpacityMasks are great, but only when used sparingly.&lt;/p&gt;
&lt;p&gt;Give it a go. I’d love to hear how it works out for you.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/j7NqLlERK-I" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/j7NqLlERK-I/fade-trimming-textblocks-in-silverlight-and-wpf</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12385/fade-trimming-textblocks-in-silverlight-and-wpf?key=b8dd663b-99af-4703-9534-5a6185d780fa</guid><pubDate>Mon, 12 Mar 2012 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12385/fade-trimming-textblocks-in-silverlight-and-wpf?key=b8dd663b-99af-4703-9534-5a6185d780fa</feedburner:origLink></item><item><title>Fixing memory leaks in RavenDB Management Studio&amp;ndash;BindableCollection</title><description>&lt;p&gt;Continuing on my last blog post in this series, which &lt;a href="http://blog.hibernatingrhinos.com/12355/fixing-memory-leaks-in-ravendb-management-studio-weakreference"&gt;I talked about the WeakReference&lt;/a&gt;, that time I’ll talk about the BindableCollection.&lt;/p&gt; &lt;p&gt;One the key goals of the new RavenDB Management Studio was to never show an old data in the studio that it’s already obsolete by the server. Say a documents was deleted/updated in the server, you want to see this change in the Management Studio immediately (or at least a few seconds later). We came up with an interesting solution for that. Each model has TimerTickedAsync method which is called both by some update event like delete a document on the studio or by a timer of 5 seconds in order to fetch changed occurred on the server. Now we need to merge the new data with the old data, remove the expired items and render the new once, but we better not render the staff that haven't been changed on a timer basis. So this is the code that we came with in order to do the range:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BindableCollection&amp;lt;T&amp;gt; : ObservableCollection&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; Func&amp;lt;T, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; primaryKeyExtractor;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; KeysComparer&amp;lt;T&amp;gt; objectComparer;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; BindableCollection(Func&amp;lt;T, &lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt; primaryKeyExtractor, KeysComparer&amp;lt;T&amp;gt; objectComparer = &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (objectComparer == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            objectComparer = &lt;span class="kwrd"&gt;new&lt;/span&gt; KeysComparer&amp;lt;T&amp;gt;(primaryKeyExtractor);
        &lt;span class="kwrd"&gt;else&lt;/span&gt;
            objectComparer.Add(primaryKeyExtractor);
        
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.primaryKeyExtractor = primaryKeyExtractor;
        &lt;span class="kwrd"&gt;this&lt;/span&gt;.objectComparer = objectComparer;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Match(ICollection&amp;lt;T&amp;gt; items, Action afterUpdate = &lt;span class="kwrd"&gt;null&lt;/span&gt;)
    {
        Execute.OnTheUI(() =&amp;gt;
        {
            var toAdd = items.Except(&lt;span class="kwrd"&gt;this&lt;/span&gt;, objectComparer).ToList();
            var toRemove = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Except(items, objectComparer).ToArray();

            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; toRemove.Length; i++)
            {
                var remove = toRemove[i];
                var add = toAdd.FirstOrDefault(x =&amp;gt; Equals(ExtractKey(x), ExtractKey(remove)));
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (add == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                {
                    Remove(remove);
                    &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
                }
                SetItem(Items.IndexOf(remove), add);
                toAdd.Remove(add);
            }
            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var add &lt;span class="kwrd"&gt;in&lt;/span&gt; toAdd)
            {
                Add(add);
            }

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (afterUpdate != &lt;span class="kwrd"&gt;null&lt;/span&gt;) afterUpdate();
        });

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (afterUpdate != &lt;span class="kwrd"&gt;null&lt;/span&gt;) afterUpdate();
    }
    ...
}&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
Note that the match method is effectively remove/add just what that is needed.&lt;/p&gt;
&lt;p&gt;Later on, we started use the Reactive Extensions’ Observable pattern in order to register to some events, and this made some of our main models to be a disposable one.&lt;/p&gt;
&lt;p&gt;So now, we had lots of models that was created by the TimerTickedAsync&amp;nbsp; but never got used in any manner. Those object was held in memory since they were registered to an events outside of the class but never got disposed (dispose unregister those events).&lt;/p&gt;
&lt;p&gt;So this fixed it: &lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Match(ICollection&amp;lt;T&amp;gt; items, Action afterUpdate = &lt;span class="kwrd"&gt;null&lt;/span&gt;)
{
    Execute.OnTheUI(() =&amp;gt;
    {
        var toAdd = items.Except(&lt;span class="kwrd"&gt;this&lt;/span&gt;, objectComparer).ToList();
        var toRemove = &lt;span class="kwrd"&gt;this&lt;/span&gt;.Except(items, objectComparer).ToArray();
        var toDispose = items.Except(toAdd, objectComparer).OfType&amp;lt;IDisposable&amp;gt;().ToArray();

        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; toRemove.Length; i++)
        {
            var remove = toRemove[i];
            var add = toAdd.FirstOrDefault(x =&amp;gt; Equals(ExtractKey(x), ExtractKey(remove)));
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (add == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                Remove(remove);
                &lt;span class="kwrd"&gt;continue&lt;/span&gt;;
            }
            SetItem(Items.IndexOf(remove), add);
            toAdd.Remove(add);
        }
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var add &lt;span class="kwrd"&gt;in&lt;/span&gt; toAdd)
        {
            Insert(0, add);
        }
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var disposable &lt;span class="kwrd"&gt;in&lt;/span&gt; toDispose)
        {
            disposable.Dispose();
        }

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (afterUpdate != &lt;span class="kwrd"&gt;null&lt;/span&gt;) afterUpdate();
    });
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now we dispose all the objects that was created on the fly and not needed anymore.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/0z0U5Eg_j94" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/0z0U5Eg_j94/fixing-memory-leaks-in-ravendb-management-studiondash-bindablecollection</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12357/fixing-memory-leaks-in-ravendb-management-studiondash-bindablecollection?key=e707b937-71ab-4cb0-b44f-be2cfc185d4d</guid><pubDate>Wed, 29 Feb 2012 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12357/fixing-memory-leaks-in-ravendb-management-studiondash-bindablecollection?key=e707b937-71ab-4cb0-b44f-be2cfc185d4d</feedburner:origLink></item><item><title>Fixing memory leaks in RavenDB Management Studio - FluidMoveBehavior</title><description>&lt;p&gt;Continuing on my last blog post in this series, which &lt;a href="http://blog.hibernatingrhinos.com/12355/fixing-memory-leaks-in-ravendb-management-studio-weakreference"&gt;I talked about the WeakReference&lt;/a&gt;, that time I’ll talk about the &lt;a href="http://blogs.msdn.com/b/expression/archive/2010/03/16/dynamic-layout-and-transitions-in-expression-blend-4.aspx"&gt;FluidMoveBehavior&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;The FluidMoveBehavior gives you a great transition effect to the items in your WrapPanel, which is in the Silverlight toolkit. The FluidMoveBehavior is part of the Expression Blend and it’s exists in the microsoft.expression.interactions.dll&lt;em&gt;.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;When I profiled the application with a memory profiler, I have some memory leaks that caused by the FluidMoveBehavior. Surprised I Googled the following “FluidMoveBehavior memory leak” and the first result was &lt;a href="http://social.expression.microsoft.com/Forums/en/blend/thread/f14d1486-24ba-447b-9712-e16f5457a08b"&gt;this&lt;/a&gt; thread, which effectively showed that this is a known issue with no fix yet.&lt;/p&gt; &lt;p&gt;So removing the FluidMoveBehavior from the Management Studio fixes a big source of memory leak. What’s interesting, that the visual effect itself of the FluidMoveBehaviour barley was needed, since we already populating the panel with items each time the panel size is changed.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/UDInwv_iEVw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/UDInwv_iEVw/fixing-memory-leaks-in-ravendb-management-studio-fluidmovebehavior</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12356/fixing-memory-leaks-in-ravendb-management-studio-fluidmovebehavior?key=ef9da14e-ff84-43f1-a5fa-aa7328bc14c6</guid><pubDate>Tue, 28 Feb 2012 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12356/fixing-memory-leaks-in-ravendb-management-studio-fluidmovebehavior?key=ef9da14e-ff84-43f1-a5fa-aa7328bc14c6</feedburner:origLink></item><item><title>Fixing memory leaks in RavenDB Management Studio - WeakReference</title><description>&lt;p&gt;Continue from the last blog post in this series, which &lt;a href="http://blog.hibernatingrhinos.com/12353/fixing-memory-leaks-in-ravendb-management-studio-weakeventlistener"&gt;I talked about the WeakEventListener&lt;/a&gt;, now I’m going to talk about using the WeakReference.&lt;/p&gt; &lt;p&gt;In the RavenDB Management Studio we have 4 pages that contains lots of data: the Home page, Collections page, Documents page and Indexes page. Once you enter to one of those pages, we’ll fetch the data from the RavenDB database but in order to avoid fetching it each time we navigate to that page the data is stored in a static variable. This way, if you re-navigate to a page, you will see the database immediately while we making a background request to RavenDB in order to give you more updated data.&lt;/p&gt; &lt;p&gt;You can look on this code for example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeModel : ViewModel
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;&lt;font style="background-color: #ffff00"&gt;static&lt;/font&gt;&lt;/span&gt; Observable&amp;lt;DocumentsModel&amp;gt; RecentDocuments { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }

    &lt;span class="kwrd"&gt;static&lt;/span&gt; HomeModel()
    {
        RecentDocuments = &lt;span class="kwrd"&gt;new&lt;/span&gt; Observable&amp;lt;DocumentsModel&amp;gt;
                          {
                            Value = &lt;span class="kwrd"&gt;new&lt;/span&gt; DocumentsModel
                                    {
                                        Header = &lt;span class="str"&gt;"Recent Documents"&lt;/span&gt;,
                                        Pager = {PageSize = 15},
                                    }
                          };
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; HomeModel()
    {
        ModelUrl = &lt;span class="str"&gt;"/home"&lt;/span&gt;;
        RecentDocuments.Value.Pager.SetTotalResults(&lt;span class="kwrd"&gt;new&lt;/span&gt; Observable&amp;lt;&lt;span class="kwrd"&gt;long&lt;/span&gt;?&amp;gt;(ApplicationModel.Database.Value.Statistics, v =&amp;gt; ((DatabaseStatistics)v).CountOfDocuments));
        ShowCreateSampleData = &lt;span class="kwrd"&gt;new&lt;/span&gt; Observable&amp;lt;&lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;(RecentDocuments.Value.Pager.TotalResults, ShouldShowCreateSampleData);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Task TimerTickedAsync()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;font style="background-color: #ffff00"&gt;RecentDocuments.Value.TimerTickedAsync();&lt;/font&gt;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;The problem is, what happening when the application consumes to much memory because of all of this static data? In that case there likely to be a performance issues. In order to avoid that, we used make static data to be a &lt;a href="http://en.wikipedia.org/wiki/Weak_reference"&gt;WeakReference&lt;/a&gt; type, so we basically say to the Silverlight GC engine: If you want to GC the data, please do so. And in this case we’ll just re-initialize it when we need the data again.&lt;/p&gt;
&lt;p&gt;This had an huge impact of the memory consumption of the Management Studio application, but we still had some memory leaks which I’ll talk about in the next blog post.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/q1o4DiJ4ZF4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/q1o4DiJ4ZF4/fixing-memory-leaks-in-ravendb-management-studio-weakreference</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12355/fixing-memory-leaks-in-ravendb-management-studio-weakreference?key=8a8909db-2f61-4337-bef4-67688dcbd2af</guid><pubDate>Mon, 27 Feb 2012 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12355/fixing-memory-leaks-in-ravendb-management-studio-weakreference?key=8a8909db-2f61-4337-bef4-67688dcbd2af</feedburner:origLink></item><item><title>Why make WeakEventListener internal?</title><description>&lt;p&gt;In the previous post I described how I used the WeakEventListener from the &lt;a href="http://silverlight.codeplex.com/"&gt;Silverlight Toolkit&lt;/a&gt; in order to solve a memory leak. This class is a very needed tool, and it’s something that is recommended to use in Silverlight applications, in order to avoid memory leaks.&lt;/p&gt; &lt;p&gt;Since this class is internal, you must copy the code from &lt;a href="https://silverlight.svn.codeplex.com/svn/Release/Silverlight4/Source/Controls.Toolkit/Common/WeakEventListener.cs"&gt;the source&lt;/a&gt; (thanks to the Microsoft Public License) to your Silverlight application. I’m not sure if this is still the case in the last version of the toolkit, which is compatible with Silverlight 5 (the source code for this is not public when I wrote this), but in any case, if you’re developing a Silverlight application, I’m pretty sure that you’ll need this class.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/yCAZilw6lqc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/yCAZilw6lqc/why-make-weakeventlistener-internal</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12354/why-make-weakeventlistener-internal?key=4a9da334-6909-463f-ae0a-5d974e0a2b33</guid><pubDate>Fri, 24 Feb 2012 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12354/why-make-weakeventlistener-internal?key=4a9da334-6909-463f-ae0a-5d974e0a2b33</feedburner:origLink></item><item><title>Fixing memory leaks in RavenDB Management Studio - WeakEventListener</title><description>&lt;p&gt;After shipping the new version of the Management Studio for RavenDB, which was part of build #573, we got reports from our users that it have some memory leaks. &lt;a href="http://issues.hibernatingrhinos.com/issue/RavenDB-29?query=leak"&gt;This&lt;/a&gt; report indicated that we have an huge memory leak in the management studio. I started to investigate this and found a bunch problems with cause it. In this blog posts series I’ll share with you what it took to fix it.&lt;/p&gt; &lt;p&gt;RavenDB Management Studio is a Silverlight based application. One of the mistakes that can be done easily in a Silverlight application (as many other platforms for UI applications) is to attach an event to an object, than discard that object. The problem is that the object will never be cleaned up from the memory, since we have a reference for it – the event listener.&lt;/p&gt; &lt;p&gt;Consider the following code for example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ModelAttacher
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty AttachObservableModelProperty =
        DependencyProperty.RegisterAttached(&lt;span class="str"&gt;"AttachObservableModel"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ModelAttacher), &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span class="kwrd"&gt;null&lt;/span&gt;, AttachObservableModelCallback));
    
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AttachObservableModelCallback(DependencyObject source, DependencyPropertyChangedEventArgs args)
    {
        var typeName = args.NewValue &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;;
        var view = source &lt;span class="kwrd"&gt;as&lt;/span&gt; FrameworkElement;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (typeName == &lt;span class="kwrd"&gt;null&lt;/span&gt; || view == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;

        var modelType = Type.GetType(&lt;span class="str"&gt;"Raven.Studio.Models."&lt;/span&gt; + typeName) ?? Type.GetType(typeName);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (modelType == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;

        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            var modelInstance = Activator.CreateInstance(modelType);
            var observableType = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Observable&amp;lt;&amp;gt;).MakeGenericType(modelType);
            var observable = Activator.CreateInstance(observableType) &lt;span class="kwrd"&gt;as&lt;/span&gt; IObservable;
            var piValue = observableType.GetProperty(&lt;span class="str"&gt;"Value"&lt;/span&gt;);
            piValue.SetValue(observable, modelInstance, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
            view.DataContext = observable;

            var model = modelInstance &lt;span class="kwrd"&gt;as&lt;/span&gt; Model;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (model == &lt;span class="kwrd"&gt;null&lt;/span&gt;) 
                &lt;span class="kwrd"&gt;return&lt;/span&gt;;
            model.ForceTimerTicked();

            SetPageTitle(modelType, modelInstance, view);
            
            &lt;font style="background-color: #ffff00"&gt;view.Loaded += ViewOnLoaded;&lt;/font&gt;
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Cannot create instance of model type: {0}"&lt;/span&gt;, modelType), ex);
        }
    }
    
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ViewOnLoaded(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, RoutedEventArgs routedEventArgs)
    {
        var view = (FrameworkElement)sender;
        var observable = view.DataContext &lt;span class="kwrd"&gt;as&lt;/span&gt; IObservable;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (observable == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        var model = (Model)observable.Value;
        model.ForceTimerTicked();

        var viewModel = model &lt;span class="kwrd"&gt;as&lt;/span&gt; ViewModel;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (viewModel == &lt;span class="kwrd"&gt;null&lt;/span&gt;) &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        viewModel.LoadModel(UrlUtil.Url);
    }&lt;/pre&gt;
&lt;p&gt;For information about the ModelAttacher pattern, take a look on &lt;a href="http://blog.hibernatingrhinos.com/11265/model-attacher-pattern-in-silverlight-applications"&gt;this&lt;/a&gt; blog post.&lt;/p&gt;
&lt;p&gt;What it means basically is that we creating a models for each page, but never dispose it. So basically each time you navigate to a page, a new view model is created for the page but the old one never got cleaned up.&lt;/p&gt;
&lt;p&gt;There was more examples like that, where we have an event keeping a reference to a dead objects. You can look on the RavenDB commits log if you interested in the details. But what is the way to solve this?&lt;/p&gt;
&lt;p&gt;In order to solve this I copy the WeakEventListener from the &lt;a href="http://silverlight.codeplex.com/"&gt;Silverlight Toolkit&lt;/a&gt;, which is internal class. Using the WeakEventListener in order to attach to objects solved the above memory issue since we don’t have a strong reference to the dead object anymore, and the GC can just clean them up.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/1XMVTUGSQBY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/1XMVTUGSQBY/fixing-memory-leaks-in-ravendb-management-studio-weakeventlistener</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12353/fixing-memory-leaks-in-ravendb-management-studio-weakeventlistener?key=e664b1d5-0cf5-469b-adbe-d047b5003ce7</guid><pubDate>Thu, 23 Feb 2012 06:22:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12353/fixing-memory-leaks-in-ravendb-management-studio-weakeventlistener?key=e664b1d5-0cf5-469b-adbe-d047b5003ce7</feedburner:origLink></item><item><title>Stress testing RavenDB</title><description>&lt;p align="left"&gt;
	The following is cross posted from &lt;a href="http://tech-rash.blogspot.com/2012/02/is-raven-db-all-its-cracked-up-to-be.html"&gt;Mark Rodseth&amp;rsquo;s blog&lt;/a&gt;&amp;nbsp;(he also posted a &lt;a href="http://tech-rash.blogspot.com/2012/02/ravendb-vs-sql-follow-up.html"&gt;follow up post with more details&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;
	Mark is a .Net Technical Architect at a digital agency named &lt;a href="http://www.fortunecookie.co.uk"&gt;Fortune Cookie&lt;/a&gt; in London. I would like to take the opportunity and thank Mark both for the grand experiment about which you are about to read and for the permission to post this in the company blog.&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		Please note: Mark or Fortune Cookie are not affiliated with either Hibernating Rhinos or RavenDB in any way.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	When a colleague mentioned&amp;nbsp; RavenDB&amp;nbsp; to me I had a poke around and discovered that it was one of the more popular open source NoSQL technologies on the market. Not only that but it was bundled with Lucene.Net Search making it Document Database coupled with Lucene search capabilities.&amp;nbsp; With an interest in NoSQL technology and a grudge match that hadn&amp;rsquo;t been settled with Lucene.Net, I set myself the challenge to swap out our SQL Search implementation with RavenDB and then do a like for like load test against the two search technologies.&lt;br /&gt;
	These are my findings from both a programmatic and performance perspective.&lt;/p&gt;
&lt;p&gt;
	&lt;br /&gt;
	&lt;b&gt;Installing RavenDB&lt;/b&gt;&lt;br /&gt;
	There isnt much to installing Raven and its pretty much a case of downloading the latest build and running the Server application.&lt;br /&gt;
	The server comes with a nice Silverlight management interface which allows you to manage all aspects of Raven Db from databases to data to indexes. All tasks have a programmatic equivalent but a decent GUI is an essential tool for noobs like myself.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Storing the Data&lt;/b&gt;&lt;br /&gt;
	My first development task was to write an import routine which parsed the property data in SQL and then add it into a Raven Database. This was fairly easy and all I needed to do was to create a POCO, plug it with data from SQL and save it using the C# Raven API. The POCO serialised into JSON data and saved as a new document in the&amp;nbsp; RavenDB.&lt;/p&gt;
&lt;p&gt;
	The main challenge here was changing my thinking from relational modelling to domain driven modelling - a paradigm shift required when moving to NoSQL - which includes concepts like aggregate roots, entities and value types. Journeying into this did get a bit metaphysical at times but here is my understanding of this new fangled schism.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Entity &lt;/b&gt;- An entity is something that has a unique identity and meaning in both the business and system context. In the property web site example, a flat or a bungalow or an office match these criteria.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Value Type &lt;/b&gt;- Part of the entity which does not require its own identity and has no domain or system relevance on its own. For example, a bedroom or a toilet.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Aggregate Root&lt;/b&gt; - Is an master entity with special rules and access permissions that relate to a grouping of similar entities. For example, a property is an aggregate of flats, bungalows and offices. This is &lt;a href="http://lostechies.com/jimmybogard/2008/05/21/entities-value-objects-aggregates-and-roots/"&gt;the best description&lt;/a&gt; of these terms I found.&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		&lt;em&gt;Hibernating Rhinos note&lt;/em&gt;: With RavenDB, we usually consider the Entity and Aggregate Root to be synonyms to a Document. There isn&amp;rsquo;t a distinction in RavenDB between the two, and they map to a RavenDB document.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	In this example, I created one Aggregate Root Entity to store all property types.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://3.bp.blogspot.com/-NhpmzrY5n78/TzEflfQhkgI/AAAAAAAAAOc/mrRPMX0shy4/s1600/poco.jpg"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-NhpmzrY5n78/TzEflfQhkgI/AAAAAAAAAOc/mrRPMX0shy4/s1600/poco.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	C# Property POCO&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Indexing the Data&lt;/b&gt;&lt;br /&gt;
	Once the Data was stored it needed to be indexed for fast search. To achieve this I had to get to grips with map reduce functions which I had seen around but avoided like the sad and lonely looking bloke** at a FUN party.&lt;br /&gt;
	The documentation is pretty spartan on the&amp;nbsp; RavenDB web site but after hacking away I finally created an index that worked on documents with nested types and allowed for spatial queries.&lt;br /&gt;
	RavenDB allows you to create indexes using Map Reduce functions in LINQ. What this allows you to do is create a Lucene index from a large, tree like structure of data. Map reduce functions give you the same capability as SQL using joins and group by statements. To create a spatial index which allowed me to search properties by type and sector (nested value types) I created an index using the following Map Reduce function.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://3.bp.blogspot.com/-rGoLp7ZAR0U/TzEgsEuu_JI/AAAAAAAAAOk/qfePslDrN9A/s1600/spatialindex.jpg"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-rGoLp7ZAR0U/TzEgsEuu_JI/AAAAAAAAAOk/qfePslDrN9A/s1600/spatialindex.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	Index created using the Raven DB Admin GUI&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		&lt;em&gt;Hibernating Rhinos note:&lt;/em&gt; a more efficient index would likely be something like:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
	&lt;pre class="csharpcode"&gt;
from r &lt;span class="kwrd"&gt;in&lt;/span&gt; docs.AssetDetailPocos
select &lt;span class="kwrd"&gt;new&lt;/span&gt;
{
  sectorname = r.Sectors,
  prnlname = r.AddressPnrls,

  r.AssetId,
  r.AskingPrice,
  r.NumberOfBedrooms,
  r.NumberOfBathRooms,
  
  
  _ = SpatialIndex.Generate(r.AssetLatitude, r.AssetLongitude)
}&lt;/pre&gt;
	&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }	&lt;/style&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
	&lt;p&gt;
		This would reduce the number of index entries and make the index smaller and faster to generate.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
	&lt;b&gt;Querying the data&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;
	Now that I had data that was indexed, the final development challenge was querying it. RavenDB has a basic search API and a Lucene Query API for more complex queries. Both allow you to write queries in LINQ. To create the kind if complex queries you would require in a property searching web site, the API was a bit lacking. To work around this I had to construct my own native Lucene queries. Fortunately the API allowed me to do so.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Performance Testing&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;
	All the pawns were now in place for my load test.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		The entire property SQL database was mirrored to&amp;nbsp; RavenDB.&lt;/li&gt;
	&lt;li&gt;
		The Search Interface now had both a SQL and a&amp;nbsp; RavenDB implementation.&lt;/li&gt;
	&lt;li&gt;
		I created a crude Web Page which allowed switching the search from SQL to&amp;nbsp; RavenDB via query string parameters and output the results using paging.To ensure maximum thrashing the load tests passed in random geo locations for proximity search and keywords for attribute search.&amp;nbsp;&lt;/li&gt;
	&lt;li&gt;
		A VM was setup and ready to face the wrath of &lt;a href="https://browsermob.com/home"&gt;BrowserMob&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	I created a ramp test scaling from 0 to 1000 concurrent users firing a single get request with no think time at the Web Page and ran it in isolation against the SQL Implementation and then in isolation against the&amp;nbsp; RavenDB Implementation. The test ran for 30 minutes.&lt;br /&gt;
	And for those of you on the edge of you seat the results where a resounding victory for&amp;nbsp; RavenDB. Some details of the load test are below but the headline is SQL choked at 250 concurrent users whereas with&amp;nbsp; RavenDB even with 1000 concurrent users the response time was below 12 seconds.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;SQL Load Test&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;
	Transactions: 111,014 (Transaction = Single Get Request)&lt;br /&gt;
	Failures: 110,286 (Any 500 or timeout)&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://3.bp.blogspot.com/-s8OGQmWkVGw/TzEEukU_EeI/AAAAAAAAAOE/KlBMa9Kx7jI/s1600/SQLDbThroughPut.jpg"&gt;&lt;img border="0" height="250" src="http://3.bp.blogspot.com/-s8OGQmWkVGw/TzEEukU_EeI/AAAAAAAAAOE/KlBMa9Kx7jI/s400/SQLDbThroughPut.jpg" width="400" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	SQL Data Throughput - Flatlines at around 250 concurrent users.&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;RavenDB Load Test&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;
	Transactions: 145,554 (Transaction = Single Get Request)&lt;br /&gt;
	Failures: 0 (Any 500 or timeout)&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://3.bp.blogspot.com/-4zPzgzwfI8U/TzEE2mxsNBI/AAAAAAAAAOM/G-f6XoqRMYE/s1600/RavenDbThroughPut.jpg"&gt;&lt;img border="0" height="252" src="http://3.bp.blogspot.com/-4zPzgzwfI8U/TzEE2mxsNBI/AAAAAAAAAOM/G-f6XoqRMYE/s400/RavenDbThroughPut.jpg" width="400" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	RavenDB Data Throughput - What the graph should look like&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;Final thoughts&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;
	RavenDB is a great document database with fairly powerful search capabilities. It has a lot of pluses and a few negative which are listed for you viewing pleasure below.&lt;br /&gt;
	Positives&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		The documentation although spartan does cover the fundamentals making it easy to get started. On some instances I did have to sniff through the source code to fathom how some things worked but that is the beauty of open source I guess.&amp;nbsp;&lt;/li&gt;
	&lt;li&gt;
		The Silverlight Admin interface is pretty sweet&amp;nbsp;&lt;/li&gt;
	&lt;li&gt;
		The Raven community (&lt;a href="http://groups.google.com/group/ravendb/"&gt;a google group&lt;/a&gt;) is very active and the couple of queries I posted were responded to almost immediately.&lt;/li&gt;
	&lt;li&gt;
		Although the API did present some challenges it both allowed you to bypass its limitations and even contribute yourself to the project.&lt;/li&gt;
	&lt;li&gt;
		The commercial licence for&amp;nbsp; RavenDB is pretty cheap at a $600 once off payment&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	Negatives&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;
		The web site documentation and content could do with an a facelift. (Saying that, I just checked the web site and it seems to have been be revamped)&lt;/li&gt;
	&lt;li&gt;
		I came a cross a bug in the Lucene.Net related to granular spatial queries which has yet to be resolved.&amp;nbsp;&amp;nbsp; Not&amp;nbsp; RavenDB&amp;#39;s fault but a dependence on third party libraries can cause issues.&amp;nbsp;&lt;/li&gt;
	&lt;li&gt;
		I struggled to find really impressive commercial reference sites. There are some testimonials but they give little information away.&amp;nbsp;&lt;/li&gt;
	&lt;li&gt;
		Sharding scares me.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
	I look forward to following the progress of&amp;nbsp; RavenDB and hopefully one day using it in a commercial project. I&amp;#39;m not at the comfort level yet for proposing it but with some more investigation and perhaps some good reference sites this could change very quickly.&lt;/p&gt;
&lt;p&gt;
	&lt;br /&gt;
	* Starry Eyed groupies sadly didn&amp;#39;t exist, nor have they ever.&lt;br /&gt;
	** Not me.&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://ravendb.net/"&gt;http://ravendb.net&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/qjBXbyFEI7g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/qjBXbyFEI7g/stress-testing-ravendb</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12321/stress-testing-ravendb?key=552896ee-35e1-41a2-8814-176f7c439e26</guid><pubDate>Fri, 10 Feb 2012 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12321/stress-testing-ravendb?key=552896ee-35e1-41a2-8814-176f7c439e26</feedburner:origLink></item><item><title>Invalid JSON results via Powershell 3</title><description>&lt;blockquote&gt;
	&lt;p&gt;
		This is a guest post by Chris, a RavenDB user, originally posted on the RavenDB group.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4&gt;
	Background&lt;/h4&gt;
&lt;p&gt;
	I&amp;rsquo;ve been fiddling with document databases for a while trying to find a way to aggregate our logs without having to demoralize everything. I started with CouchDB and because of the odd status of the project with the founder abandoning it and since I work in a Windows world, going with Raven ultimately seemed like a wholly better solution &amp;ndash; all the goods of Couch plus a .Net API.&lt;/p&gt;
&lt;p&gt;
	I built a data model in C# and used a CSV library to push a few hundred thousand records into Raven. The goal is to allow support engineers to query this log information with some simple PowerShell one-liners.&lt;/p&gt;
&lt;p&gt;
	I thought parsing 100megs of CSV and jamming in the thousands of corresponding documents would be the difficult part to figure out and the one-liners would be a couple hours of work at most.&lt;/p&gt;
&lt;h4&gt;
	The Problem&lt;/h4&gt;
&lt;p&gt;
	Yes, it was a bit challenging to build an efficient importer, but most of that was due to my limited knowledge of C#. I thought it was still not working when I started to build my Posh one-liners and some queries were returning invalid JSON. The PowerShell 3 CTP introduce some new cmdlets for handling JSON and one specifically for executing HTTP Rest API calls &amp;ndash; Invoke-RestMethod (alias irm). IRM is 100 times more user friendly than CURL and it even goes a step above and beyond by automatically deserializing the content returned. So, it&amp;rsquo;s extremely easy to consume JSON via a REST API, but I kept running into an issue where Posh would throw an error that there was no Results (the deserialized JSON) property on the object. I must have been pushing in bad data &amp;ndash; garbage in equals garbage out.&lt;/p&gt;
&lt;p&gt;
	I thought the HTML in some of the log values was invalidating the JSON string. I deleted all the documents, added a call to HTTPEncode on all strings before Storing it to Raven, then I reloaded the records. I ended up with the same results; or, lack of Results property in this case.&lt;/p&gt;
&lt;p&gt;
	The Invoke-RestMethod cmdlet did return what looked like a valid JSON string, so I dropped it into Notepad++ and turned on JavaScript syntax highlighting and went through the string. I found the culprit.&lt;/p&gt;
&lt;p&gt;
	&amp;quot;SkippedResults:0,&lt;/p&gt;
&lt;p&gt;
	There was a missing quote around a key name. I almost posted this as a RavenDB bug, but I checked the raw HTTP response in Fiddler and found that the quote existed.&lt;/p&gt;
&lt;h4&gt;
	What do to about it&lt;/h4&gt;
&lt;p&gt;
	I am working with a Technology Preview release of Powershell 3, so I checked Connect and found a similar &lt;a href="https://connect.microsoft.com/PowerShell/feedback/details/716283/invoke-restmethod-returns-incorrect-data" target="_blank"&gt;report&lt;/a&gt; of missing characters in content deserialization.&lt;/p&gt;
&lt;p&gt;
	&amp;ldquo;It seems that the last byte of the second HTTP response packet is being dropped by powershell. This only seems to happen when the second response packet is smaller than the first.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;
	Microsoft closed this issue as &amp;ldquo;Won&amp;rsquo;t Fix&amp;rdquo; and suggested using Invoke-WebRequest instead. Invoke-WebRequest removes all the magic of Invoke-RestMethod and just gets raw HTTP content. I piped the Content parameter to the, also new to Powershell 3, cmdlet ConvertFrom-Json and got proper deserializedJSON.&lt;/p&gt;
&lt;p&gt;
	$c = Invoke-WebRequest &amp;quot;http://localhost:8080/indexes/vovici/Logs/process?query=customer:blah&amp;quot;&lt;br /&gt;
	$r = $c.content | convertfrom-json&lt;/p&gt;
&lt;p&gt;
	So, it&amp;rsquo;s an extra step, but if you want to reliably access RavenDB&amp;rsquo;s HTTP API via PowerShell 3 that seems to be the way to do it.&lt;/p&gt;
&lt;p&gt;
	&lt;span style="background-color:yellow;"&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; It does look like MS fixed the lost character issue in the Invoke-RestMethod cmdlet in the latest beta release. I can pull down 1024 documents with one web request and get a usable, deserialized Object[].&lt;/span&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/xDf9uSygjc4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/xDf9uSygjc4/invalid-json-results-via-powershell-3</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/12289/invalid-json-results-via-powershell-3?key=85df1252-04fc-48b1-98db-2e84da3e2d9b</guid><pubDate>Mon, 30 Jan 2012 09:28:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/12289/invalid-json-results-via-powershell-3?key=85df1252-04fc-48b1-98db-2e84da3e2d9b</feedburner:origLink></item><item><title>Model Attacher pattern in Silverlight applications</title><description>&lt;p&gt;A while ago, when we started to develop our next version of RavenDB Studio, one of our goals was to make its code as simple as possible. That way, we ensure that it is easy to understand what is going on, so making changes to the Studio should be a trivial task.&lt;/p&gt; &lt;p&gt;In order to achieve that, we decided to not use any MVVM toolkits, but simply use a simple pages (views) and attach a model to them. In this approach, every view (page) know how to resolve its view-model by itself. This makes the Silverlight code much more simple, since it let’s you open a specific view by just navigating to its relative URL. &lt;/p&gt; &lt;p&gt;In order to make this possible we have a ModelAttacher.AttachModel attached property on the page, which takes care of instantiating the view-model and attach it to the page’s DataContext property. &lt;/p&gt; &lt;p&gt;Take a look on the following tipical view (page) in order to see it in action:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Infrastructure:View&lt;/span&gt; &lt;span class="attr"&gt;x:Class&lt;/span&gt;&lt;span class="kwrd"&gt;="Raven.Studio.Views.Home"&lt;/span&gt;
                     &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&lt;/span&gt;
                     &lt;span class="attr"&gt;xmlns:x&lt;/span&gt;&lt;span class="kwrd"&gt;="http://schemas.microsoft.com/winfx/2006/xaml"&lt;/span&gt;
                     &lt;span class="attr"&gt;xmlns:Infrastructure&lt;/span&gt;&lt;span class="kwrd"&gt;="clr-namespace:Raven.Studio.Infrastructure"&lt;/span&gt;
                     &lt;span class="attr"&gt;Title&lt;/span&gt;&lt;span class="kwrd"&gt;="Home"&lt;/span&gt;
                     &lt;span class="attr"&gt;Style&lt;/span&gt;&lt;span class="kwrd"&gt;="{StaticResource PageStyle}"&lt;/span&gt;
                     &lt;span class="attr"&gt;Infrastructure:ModelAttacher&lt;/span&gt;.&lt;span class="attr"&gt;AttachModel&lt;/span&gt;&lt;span class="kwrd"&gt;="HomeModel"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Infrastructure:View&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;In this example, we have an empty Home view, which is make a use of a HomeModel. The ModelAttacher’s job here is to create an instance of the HomeModel class and attach it to the View.DataContext property. (The view is a simple class that derives from Page.)&lt;/p&gt;
&lt;p&gt;This is how ModelAttacher works, in order to achieve this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Raven.Studio.Infrastructure
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ModelAttacher
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DependencyProperty AttachModelProperty =
            DependencyProperty.RegisterAttached(&lt;span class="str"&gt;"AttachModel"&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ModelAttacher), &lt;span class="kwrd"&gt;new&lt;/span&gt; PropertyMetadata(&lt;span class="kwrd"&gt;null&lt;/span&gt;, AttachModelCallback));
        
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AttachModelCallback(DependencyObject source, DependencyPropertyChangedEventArgs args)
        {
            var typeName = args.NewValue &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt;;
            var view = source &lt;span class="kwrd"&gt;as&lt;/span&gt; FrameworkElement;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (typeName == &lt;span class="kwrd"&gt;null&lt;/span&gt; || view == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                &lt;span class="kwrd"&gt;return&lt;/span&gt;;

            var modelType = Type.GetType(&lt;span class="str"&gt;"Raven.Studio.Models."&lt;/span&gt; + typeName) ?? Type.GetType(typeName);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (modelType == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                &lt;span class="kwrd"&gt;return&lt;/span&gt;;

            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                var model = Activator.CreateInstance(modelType);
                view.DataContext = model;
            }
            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
            {
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidOperationException(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Cannot create instance of model type: {0}"&lt;/span&gt;, modelType), ex);
            }
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetAttachModel(UIElement element)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;)element.GetValue(AttachModelProperty);
        }

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetAttachModel(UIElement element, &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)
        {
            element.SetValue(AttachModelProperty, &lt;span class="kwrd"&gt;value&lt;/span&gt;);
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Now in order to attach a model to its view, we need to just add the attached property to the view element:&amp;nbsp; Infrastructure:ModelAttacher.AttachModel="HomeModel".&lt;/p&gt;
&lt;p&gt;Please note that in this case any view-model has to have a default (parameters-less) constructor. In order to solve that, what we have done in RavenDB Studio is to have a ModelBase class for our view-models which make sure to expose all our common model dependencies.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/9MXyu6u43hM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/9MXyu6u43hM/model-attacher-pattern-in-silverlight-applications</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/11265/model-attacher-pattern-in-silverlight-applications?key=d2f671da-cd86-4717-887f-973536612d26</guid><pubDate>Thu, 24 Nov 2011 06:49:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/11265/model-attacher-pattern-in-silverlight-applications?key=d2f671da-cd86-4717-887f-973536612d26</feedburner:origLink></item><item><title>XAML Magic: Turning an Ugly Silverlight Duckling into a Beautiful Photoshopped Swan</title><description>&lt;blockquote&gt; &lt;p&gt;This is a guest post by &lt;a href="http://blog.functionalfun.net"&gt;Samuel Jack&lt;/a&gt;, who had done a lot of work on the new UI for RavenDB.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Three weeks ago Ayende put out a request for &lt;a href="http://ayende.com/blog/111617/looking-for-a-xaml-expert"&gt;help in turning an ugly duckling into a beautiful swan&lt;/a&gt;, and I, rather nervously, signed up for the job. The ugly duckling in question was Raven Studio, the Silverlight-based management UI for Raven Db. The nerves were a result of doubting that my limited graphic design skills were up to the job. But when Ayende assured me that he had a proto-type swan in the form of a Photoshop design, drawn up by a bona-fide, turtle-neck-wearing designer, they were calmed. Marginally.&lt;/p&gt; &lt;p&gt;Because the design Ayende had was for the new-look RavenDb website. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_2.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb.png" width="600" height="457"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;He wanted me to take the look and feel and transfer it to the Silverlight Raven Studio application. Which, when he handed it over to me, looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_4.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_1.png" width="600" height="440"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ahh! Where to start?&lt;/p&gt; &lt;h4&gt;Photoshop for Developer Dummies&lt;/h4&gt; &lt;p&gt;To ease myself in, I got started by simply trying to imitate parts of the Photoshop design in XAML, beginning with the header bar at the very top of the page. Not being a designer myself, I’m rather like a duck out of water when it comes to Photoshop, but I’ve at least got the basics sussed.&lt;/p&gt; &lt;p&gt;The thing to understand is that designers construct Photoshop images like onions, layer upon layer, sometimes eye-watering in complexity, and to reproduce the design, you have to peel down through the layers. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_8.png"&gt;&lt;img style="display: inline; float: left" title="Photoshop Layer Basics" alt="Photoshop Layer Basics" align="left" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_3.png" width="450" height="241"&gt;&lt;/a&gt;First go to Photoshop’s Layers pane, and make sure all the layers are unlocked. This allows the Move Layer tool to come into play, not to move layers, but identify layers by selecting them in the Layers pane when you click the corresponding part of the image. Once you’ve identified a layer, Alt-Click it, and all other layers in the image will be hidden, allowing you to figure out exactly how the thing should look.&lt;/p&gt; &lt;p&gt;Mostly when I’m paring down Photoshop layers I’m looking to isolate them so that I can figure out the colour gradients they use. You could, of course, navigate your way through Photoshop’s dialogs to read off the exact RGB values. Or, if you can get the layer on its lonesome, you can use Expression Blend’s Gradient Dropper tool. &lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_2.png"&gt;&lt;img style="margin: 5px 0px; display: inline; float: right" title="GradientEyeDropper" alt="GradientEyeDropper" align="right" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_thumb.png" width="240" height="221"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a brilliant little timesaver. In the Blend Property pane, select the Brush property of your choice, put it into Gradient mode, click the Gradient Dropper tool, then drag over any area on screen, and Blend will reproduce the gradient under the cursor in XAML form.&lt;/p&gt; &lt;p&gt;After all that, I have the first feather of the new swan: a header bar matching the Photoshop design. Well, the background of the header bar. It needs fleshing out with some buttons.&lt;/p&gt; &lt;h4&gt;Let it Live: Control Templates and Visual States&lt;/h4&gt; &lt;p&gt;Silverlight, following WPF, has the concept of look-less controls. That is, the Controls (take Button as an example) manage their behaviour (Buttons respond to mouse clicks by executing commands) but don’t define how they are rendered on screen. That is left to the control’s &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_basics"&gt;Style&lt;/a&gt;, and specifically its &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_controltemplates"&gt;ControlTemplate&lt;/a&gt;. The ControlTemplate defines the visual tree of all the UI elements needed to present the control and make it look snazzy. With a little patience, some assistance from Expression Blend, and plenty of application of the Gradient Dropper tool, it’s possible to take the built-in controls and make them look and feel just how the designer ordered.&lt;/p&gt; &lt;p&gt;I wanted Buttons that look like those in the header bar of the Photoshop design, but when the corresponding page is selected, they should change to have a background gradient with colours like the RavenDb logo.&lt;/p&gt; &lt;p&gt;When restyling a Control, it’s best to start by modifying the existing style. This way you can be sure you won’t miss an aspect of the control’s behaviour that you might otherwise forget. Blend makes this easy by giving you the option of editing a copy of the Control’s current ControlTemplate (right-click on it in the Objects and Timeline View, then select Edit Template &amp;gt; Edit a Copy). There are occasions when that little trick has failed, and I’ve ended up with an empty control template. But MSDN has come through for me then: it has a whole section containing the &lt;a href="http://msdn.microsoft.com/en-us/library/cc278075(v=VS.95).aspx"&gt;default Styles and Control Templates for all the built-in controls&lt;/a&gt;, like this one for &lt;a href="http://msdn.microsoft.com/en-us/library/cc278069(v=VS.95).aspx"&gt;Button&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Part of the ControlTemplate defines how the control looks in its various states, when the mouse is over it, when it has focus, or when it is selected, for example. The Control itself is responsible for indicating when it has entered each state. As a designer, it’s your job to specify Storyboards that are activated each time particular states are entered. Each Storyboard can animate whichever properties it likes to achieve the desired effect – in my Buttons, for example, I animate the opacity property of a Border element to fade in a coloured background indicating that it is selected. All this is overseen by the VisualStateManager, of which, more &lt;a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspx"&gt;here&lt;/a&gt;. Naturally, Expression Blend has great editing support for visual states. Read John Papa’s &lt;a href="http://visualstudiomagazine.com/articles/2011/09/20/retemplating-in-blend.aspx"&gt;tutorial&lt;/a&gt; to learn more.&lt;/p&gt; &lt;p&gt;So now I have a header bar with buttons that change colour when the corresponding page is selected. Where next?&lt;/p&gt; &lt;h4&gt;Textured Backgrounds&lt;/h4&gt; &lt;p&gt;Well, that page background could do with spicing up. The Photoshop design has a nice textured background, which I extracted to a PNG file that Silverlight would understand by hiding every layer except the background, then using Photoshop’s “Save for Web &amp;amp; Devices” feature. &lt;/p&gt; &lt;p&gt;The thing about textured backgrounds is that you do want them to cover the whole of the page background, which means tiling the texture to fill all the space. WPF makes this easy with its ImageBrush, which has a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.tilemode.aspx"&gt;TileMode&lt;/a&gt; property, which, when set to a value other than None, automatically repeats the image over the whole area to be painted by the brush. Silverlight has ImageBrushes, but they don’t support tiling out of the box. Fortunately, Phil Middlemiss has supplied what is lacking in the form of the &lt;a href="http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html"&gt;TiledBGControl&lt;/a&gt; which does exactly what I need – you should take a look: it makes clever use of Silverlight’s pixel shader effects.&lt;/p&gt; &lt;p&gt;This is what we’ve got so far. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_10.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_4.png" width="600" height="334"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;The Index Editor Page, Before and After&lt;/h4&gt; &lt;p&gt;Here are a couple of other pages I’ve beautified. First, the Index Editor page, as it was before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_12.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_5.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And now:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_14.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_6.png" width="600" height="365"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Again, it was a challenge knowing where to apply my beautician’s brush first. I settled on adding the header bar at the top, and I then realised it could double up as a toolbar. Originally the page had no header at all, but by having a bread-crumb bar in the header it helps to give the user a bit more context when they’re looking at the page, as well as making it easier to navigate around.&lt;/p&gt; &lt;h4&gt;Inspiration and Icons&lt;/h4&gt; &lt;p&gt;Since my graphic-design skills are so underdeveloped, I borrow ideas shamelessly wherever I find something that fits. You may recognise the styling of the toolbar buttons in the Index page header bar as being remarkably similar to the ones on the Google Chrome toolbar. Yes – Expression Blend’s Gradient dropper does work on live applications too! Two places to check out if you find yourself short on inspiration are &lt;a href="http://quince.infragistics.com/"&gt;Quince&lt;/a&gt; and &lt;a href="http://patterntap.com/"&gt;Pattern Tab&lt;/a&gt; which both catalogue examples of user interface and user experience design from across the web. Pattern Tab especially has myriad examples of beautiful UIs.&lt;/p&gt; &lt;p&gt;In the past I’ve struggled to find icons for my projects, but I’ve recently discovered two great sources: &lt;a href="http://www.iconfinder.com/"&gt;IconFinder.com&lt;/a&gt; and &lt;a href="http://www.iconarchive.com/"&gt;IconArchive.com&lt;/a&gt;. Both have excellent search facilities (which is often what’s missing from the commercial collections you buy and download to your machine in a whacking great zip file), and are careful to call out the license attached to each icon. A surprisingly large number are licensed so that they can be used without charge in commercial products.&lt;/p&gt; &lt;h4&gt;A XAML Tip&lt;/h4&gt; &lt;p&gt;The nice thing about styling an application is that it gets easier with every page you complete. Once you’ve settled on a look for a particular kind of element, you can repeat that look on every page. Silverlight’s support for Styles and Resources makes this very easy. And I have a tip that can make it easier still. &lt;/p&gt; &lt;p&gt;I put all my styles into a single resource dictionary, Styles.xaml which I merge into my App.xaml resource dictionary. I then name all my Styles, Brushes, etc. using a hierarchical naming convention. So Styles all begin with “Style_”, Styles for Buttons would all begin “Style_Button”, and then would come the styles for different purposes: “Style_Button_Toolbar”, “Style_Button_Hero” (for those big red buttons in your app that the hero uses to save the world), etc.. The pay-off for using this convention comes when you’re hand-editing XAML and making use of Resharper’s XAML intellisense. Type “{StaticResource Style_[ControlType]” and Resharper instantly presents you with a list of all the styles that might apply.&lt;/p&gt; &lt;h4&gt;A Parting Screenshot&lt;/h4&gt; &lt;p&gt;To finish, here’s one more before and after comparison, this time of the Edit Document page. Before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_16.png"&gt;&lt;img style="display: inline" title="Edit Document Page - Before" alt="Edit Document Page - Before" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_7.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And after:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_20.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_9.png" width="600" height="362"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can begin to sense the benefit of using a consistent set of styles, as it brings a harmonious feel to the whole application.&lt;/p&gt; &lt;p&gt;I hope you’ve enjoyed this whistle-stop tour of the Raven Studio beautification process. Remember that all the code is available on &lt;a href="https://github.com/ravendb/studio"&gt;GitHub&lt;/a&gt;. We’d love to hear what you think.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/NMPgSjKQPZs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/NMPgSjKQPZs/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</guid><pubDate>Mon, 24 Oct 2011 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</feedburner:origLink></item><item><title>XAML Magic: Turning an Ugly Silverlight Duckling into a Beautiful Photoshopped Swan</title><description>&lt;blockquote&gt; &lt;p&gt;This is a guest post by &lt;a href="http://blog.functionalfun.net"&gt;Samuel Jack&lt;/a&gt;, who had done a lot of work on the new UI for RavenDB.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Three weeks ago Ayende put out a request for &lt;a href="http://ayende.com/blog/111617/looking-for-a-xaml-expert"&gt;help in turning an ugly duckling into a beautiful swan&lt;/a&gt;, and I, rather nervously, signed up for the job. The ugly duckling in question was Raven Studio, the Silverlight-based management UI for Raven Db. The nerves were a result of doubting that my limited graphic design skills were up to the job. But when Ayende assured me that he had a proto-type swan in the form of a Photoshop design, drawn up by a bona-fide, turtle-neck-wearing designer, they were calmed. Marginally.&lt;/p&gt; &lt;p&gt;Because the design Ayende had was for the new-look RavenDb website. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_2.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb.png" width="600" height="457"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;He wanted me to take the look and feel and transfer it to the Silverlight Raven Studio application. Which, when he handed it over to me, looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_4.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_1.png" width="600" height="440"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ahh! Where to start?&lt;/p&gt; &lt;h4&gt;Photoshop for Developer Dummies&lt;/h4&gt; &lt;p&gt;To ease myself in, I got started by simply trying to imitate parts of the Photoshop design in XAML, beginning with the header bar at the very top of the page. Not being a designer myself, I’m rather like a duck out of water when it comes to Photoshop, but I’ve at least got the basics sussed.&lt;/p&gt; &lt;p&gt;The thing to understand is that designers construct Photoshop images like onions, layer upon layer, sometimes eye-watering in complexity, and to reproduce the design, you have to peel down through the layers. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_8.png"&gt;&lt;img style="display: inline; float: left" title="Photoshop Layer Basics" alt="Photoshop Layer Basics" align="left" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_3.png" width="450" height="241"&gt;&lt;/a&gt;First go to Photoshop’s Layers pane, and make sure all the layers are unlocked. This allows the Move Layer tool to come into play, not to move layers, but identify layers by selecting them in the Layers pane when you click the corresponding part of the image. Once you’ve identified a layer, Alt-Click it, and all other layers in the image will be hidden, allowing you to figure out exactly how the thing should look.&lt;/p&gt; &lt;p&gt;Mostly when I’m paring down Photoshop layers I’m looking to isolate them so that I can figure out the colour gradients they use. You could, of course, navigate your way through Photoshop’s dialogs to read off the exact RGB values. Or, if you can get the layer on its lonesome, you can use Expression Blend’s Gradient Dropper tool. &lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_2.png"&gt;&lt;img style="margin: 5px 0px; display: inline; float: right" title="GradientEyeDropper" alt="GradientEyeDropper" align="right" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_thumb.png" width="240" height="221"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a brilliant little timesaver. In the Blend Property pane, select the Brush property of your choice, put it into Gradient mode, click the Gradient Dropper tool, then drag over any area on screen, and Blend will reproduce the gradient under the cursor in XAML form.&lt;/p&gt; &lt;p&gt;After all that, I have the first feather of the new swan: a header bar matching the Photoshop design. Well, the background of the header bar. It needs fleshing out with some buttons.&lt;/p&gt; &lt;h4&gt;Let it Live: Control Templates and Visual States&lt;/h4&gt; &lt;p&gt;Silverlight, following WPF, has the concept of look-less controls. That is, the Controls (take Button as an example) manage their behaviour (Buttons respond to mouse clicks by executing commands) but don’t define how they are rendered on screen. That is left to the control’s &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_basics"&gt;Style&lt;/a&gt;, and specifically its &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_controltemplates"&gt;ControlTemplate&lt;/a&gt;. The ControlTemplate defines the visual tree of all the UI elements needed to present the control and make it look snazzy. With a little patience, some assistance from Expression Blend, and plenty of application of the Gradient Dropper tool, it’s possible to take the built-in controls and make them look and feel just how the designer ordered.&lt;/p&gt; &lt;p&gt;I wanted Buttons that look like those in the header bar of the Photoshop design, but when the corresponding page is selected, they should change to have a background gradient with colours like the RavenDb logo.&lt;/p&gt; &lt;p&gt;When restyling a Control, it’s best to start by modifying the existing style. This way you can be sure you won’t miss an aspect of the control’s behaviour that you might otherwise forget. Blend makes this easy by giving you the option of editing a copy of the Control’s current ControlTemplate (right-click on it in the Objects and Timeline View, then select Edit Template &amp;gt; Edit a Copy). There are occasions when that little trick has failed, and I’ve ended up with an empty control template. But MSDN has come through for me then: it has a whole section containing the &lt;a href="http://msdn.microsoft.com/en-us/library/cc278075(v=VS.95).aspx"&gt;default Styles and Control Templates for all the built-in controls&lt;/a&gt;, like this one for &lt;a href="http://msdn.microsoft.com/en-us/library/cc278069(v=VS.95).aspx"&gt;Button&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Part of the ControlTemplate defines how the control looks in its various states, when the mouse is over it, when it has focus, or when it is selected, for example. The Control itself is responsible for indicating when it has entered each state. As a designer, it’s your job to specify Storyboards that are activated each time particular states are entered. Each Storyboard can animate whichever properties it likes to achieve the desired effect – in my Buttons, for example, I animate the opacity property of a Border element to fade in a coloured background indicating that it is selected. All this is overseen by the VisualStateManager, of which, more &lt;a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspx"&gt;here&lt;/a&gt;. Naturally, Expression Blend has great editing support for visual states. Read John Papa’s &lt;a href="http://visualstudiomagazine.com/articles/2011/09/20/retemplating-in-blend.aspx"&gt;tutorial&lt;/a&gt; to learn more.&lt;/p&gt; &lt;p&gt;So now I have a header bar with buttons that change colour when the corresponding page is selected. Where next?&lt;/p&gt; &lt;h4&gt;Textured Backgrounds&lt;/h4&gt; &lt;p&gt;Well, that page background could do with spicing up. The Photoshop design has a nice textured background, which I extracted to a PNG file that Silverlight would understand by hiding every layer except the background, then using Photoshop’s “Save for Web &amp;amp; Devices” feature. &lt;/p&gt; &lt;p&gt;The thing about textured backgrounds is that you do want them to cover the whole of the page background, which means tiling the texture to fill all the space. WPF makes this easy with its ImageBrush, which has a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.tilemode.aspx"&gt;TileMode&lt;/a&gt; property, which, when set to a value other than None, automatically repeats the image over the whole area to be painted by the brush. Silverlight has ImageBrushes, but they don’t support tiling out of the box. Fortunately, Phil Middlemiss has supplied what is lacking in the form of the &lt;a href="http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html"&gt;TiledBGControl&lt;/a&gt; which does exactly what I need – you should take a look: it makes clever use of Silverlight’s pixel shader effects.&lt;/p&gt; &lt;p&gt;This is what we’ve got so far. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_10.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_4.png" width="600" height="334"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;The Index Editor Page, Before and After&lt;/h4&gt; &lt;p&gt;Here are a couple of other pages I’ve beautified. First, the Index Editor page, as it was before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_12.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_5.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And now:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_14.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_6.png" width="600" height="365"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Again, it was a challenge knowing where to apply my beautician’s brush first. I settled on adding the header bar at the top, and I then realised it could double up as a toolbar. Originally the page had no header at all, but by having a bread-crumb bar in the header it helps to give the user a bit more context when they’re looking at the page, as well as making it easier to navigate around.&lt;/p&gt; &lt;h4&gt;Inspiration and Icons&lt;/h4&gt; &lt;p&gt;Since my graphic-design skills are so underdeveloped, I borrow ideas shamelessly wherever I find something that fits. You may recognise the styling of the toolbar buttons in the Index page header bar as being remarkably similar to the ones on the Google Chrome toolbar. Yes – Expression Blend’s Gradient dropper does work on live applications too! Two places to check out if you find yourself short on inspiration are &lt;a href="http://quince.infragistics.com/"&gt;Quince&lt;/a&gt; and &lt;a href="http://patterntap.com/"&gt;Pattern Tab&lt;/a&gt; which both catalogue examples of user interface and user experience design from across the web. Pattern Tab especially has myriad examples of beautiful UIs.&lt;/p&gt; &lt;p&gt;In the past I’ve struggled to find icons for my projects, but I’ve recently discovered two great sources: &lt;a href="http://www.iconfinder.com/"&gt;IconFinder.com&lt;/a&gt; and &lt;a href="http://www.iconarchive.com/"&gt;IconArchive.com&lt;/a&gt;. Both have excellent search facilities (which is often what’s missing from the commercial collections you buy and download to your machine in a whacking great zip file), and are careful to call out the license attached to each icon. A surprisingly large number are licensed so that they can be used without charge in commercial products.&lt;/p&gt; &lt;h4&gt;A XAML Tip&lt;/h4&gt; &lt;p&gt;The nice thing about styling an application is that it gets easier with every page you complete. Once you’ve settled on a look for a particular kind of element, you can repeat that look on every page. Silverlight’s support for Styles and Resources makes this very easy. And I have a tip that can make it easier still. &lt;/p&gt; &lt;p&gt;I put all my styles into a single resource dictionary, Styles.xaml which I merge into my App.xaml resource dictionary. I then name all my Styles, Brushes, etc. using a hierarchical naming convention. So Styles all begin with “Style_”, Styles for Buttons would all begin “Style_Button”, and then would come the styles for different purposes: “Style_Button_Toolbar”, “Style_Button_Hero” (for those big red buttons in your app that the hero uses to save the world), etc.. The pay-off for using this convention comes when you’re hand-editing XAML and making use of Resharper’s XAML intellisense. Type “{StaticResource Style_[ControlType]” and Resharper instantly presents you with a list of all the styles that might apply.&lt;/p&gt; &lt;h4&gt;A Parting Screenshot&lt;/h4&gt; &lt;p&gt;To finish, here’s one more before and after comparison, this time of the Edit Document page. Before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_16.png"&gt;&lt;img style="display: inline" title="Edit Document Page - Before" alt="Edit Document Page - Before" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_7.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And after:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_20.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_9.png" width="600" height="362"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can begin to sense the benefit of using a consistent set of styles, as it brings a harmonious feel to the whole application.&lt;/p&gt; &lt;p&gt;I hope you’ve enjoyed this whistle-stop tour of the Raven Studio beautification process. Remember that all the code is available on &lt;a href="https://github.com/ravendb/studio"&gt;GitHub&lt;/a&gt;. We’d love to hear what you think.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/NMPgSjKQPZs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/NMPgSjKQPZs/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</guid><pubDate>Mon, 24 Oct 2011 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</feedburner:origLink></item><item><title>XAML Magic: Turning an Ugly Silverlight Duckling into a Beautiful Photoshopped Swan</title><description>&lt;blockquote&gt; &lt;p&gt;This is a guest post by &lt;a href="http://blog.functionalfun.net"&gt;Samuel Jack&lt;/a&gt;, who had done a lot of work on the new UI for RavenDB.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Three weeks ago Ayende put out a request for &lt;a href="http://ayende.com/blog/111617/looking-for-a-xaml-expert"&gt;help in turning an ugly duckling into a beautiful swan&lt;/a&gt;, and I, rather nervously, signed up for the job. The ugly duckling in question was Raven Studio, the Silverlight-based management UI for Raven Db. The nerves were a result of doubting that my limited graphic design skills were up to the job. But when Ayende assured me that he had a proto-type swan in the form of a Photoshop design, drawn up by a bona-fide, turtle-neck-wearing designer, they were calmed. Marginally.&lt;/p&gt; &lt;p&gt;Because the design Ayende had was for the new-look RavenDb website. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_2.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb.png" width="600" height="457"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;He wanted me to take the look and feel and transfer it to the Silverlight Raven Studio application. Which, when he handed it over to me, looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_4.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_1.png" width="600" height="440"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ahh! Where to start?&lt;/p&gt; &lt;h4&gt;Photoshop for Developer Dummies&lt;/h4&gt; &lt;p&gt;To ease myself in, I got started by simply trying to imitate parts of the Photoshop design in XAML, beginning with the header bar at the very top of the page. Not being a designer myself, I’m rather like a duck out of water when it comes to Photoshop, but I’ve at least got the basics sussed.&lt;/p&gt; &lt;p&gt;The thing to understand is that designers construct Photoshop images like onions, layer upon layer, sometimes eye-watering in complexity, and to reproduce the design, you have to peel down through the layers. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_8.png"&gt;&lt;img style="display: inline; float: left" title="Photoshop Layer Basics" alt="Photoshop Layer Basics" align="left" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_3.png" width="450" height="241"&gt;&lt;/a&gt;First go to Photoshop’s Layers pane, and make sure all the layers are unlocked. This allows the Move Layer tool to come into play, not to move layers, but identify layers by selecting them in the Layers pane when you click the corresponding part of the image. Once you’ve identified a layer, Alt-Click it, and all other layers in the image will be hidden, allowing you to figure out exactly how the thing should look.&lt;/p&gt; &lt;p&gt;Mostly when I’m paring down Photoshop layers I’m looking to isolate them so that I can figure out the colour gradients they use. You could, of course, navigate your way through Photoshop’s dialogs to read off the exact RGB values. Or, if you can get the layer on its lonesome, you can use Expression Blend’s Gradient Dropper tool. &lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_2.png"&gt;&lt;img style="margin: 5px 0px; display: inline; float: right" title="GradientEyeDropper" alt="GradientEyeDropper" align="right" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_thumb.png" width="240" height="221"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a brilliant little timesaver. In the Blend Property pane, select the Brush property of your choice, put it into Gradient mode, click the Gradient Dropper tool, then drag over any area on screen, and Blend will reproduce the gradient under the cursor in XAML form.&lt;/p&gt; &lt;p&gt;After all that, I have the first feather of the new swan: a header bar matching the Photoshop design. Well, the background of the header bar. It needs fleshing out with some buttons.&lt;/p&gt; &lt;h4&gt;Let it Live: Control Templates and Visual States&lt;/h4&gt; &lt;p&gt;Silverlight, following WPF, has the concept of look-less controls. That is, the Controls (take Button as an example) manage their behaviour (Buttons respond to mouse clicks by executing commands) but don’t define how they are rendered on screen. That is left to the control’s &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_basics"&gt;Style&lt;/a&gt;, and specifically its &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_controltemplates"&gt;ControlTemplate&lt;/a&gt;. The ControlTemplate defines the visual tree of all the UI elements needed to present the control and make it look snazzy. With a little patience, some assistance from Expression Blend, and plenty of application of the Gradient Dropper tool, it’s possible to take the built-in controls and make them look and feel just how the designer ordered.&lt;/p&gt; &lt;p&gt;I wanted Buttons that look like those in the header bar of the Photoshop design, but when the corresponding page is selected, they should change to have a background gradient with colours like the RavenDb logo.&lt;/p&gt; &lt;p&gt;When restyling a Control, it’s best to start by modifying the existing style. This way you can be sure you won’t miss an aspect of the control’s behaviour that you might otherwise forget. Blend makes this easy by giving you the option of editing a copy of the Control’s current ControlTemplate (right-click on it in the Objects and Timeline View, then select Edit Template &amp;gt; Edit a Copy). There are occasions when that little trick has failed, and I’ve ended up with an empty control template. But MSDN has come through for me then: it has a whole section containing the &lt;a href="http://msdn.microsoft.com/en-us/library/cc278075(v=VS.95).aspx"&gt;default Styles and Control Templates for all the built-in controls&lt;/a&gt;, like this one for &lt;a href="http://msdn.microsoft.com/en-us/library/cc278069(v=VS.95).aspx"&gt;Button&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Part of the ControlTemplate defines how the control looks in its various states, when the mouse is over it, when it has focus, or when it is selected, for example. The Control itself is responsible for indicating when it has entered each state. As a designer, it’s your job to specify Storyboards that are activated each time particular states are entered. Each Storyboard can animate whichever properties it likes to achieve the desired effect – in my Buttons, for example, I animate the opacity property of a Border element to fade in a coloured background indicating that it is selected. All this is overseen by the VisualStateManager, of which, more &lt;a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspx"&gt;here&lt;/a&gt;. Naturally, Expression Blend has great editing support for visual states. Read John Papa’s &lt;a href="http://visualstudiomagazine.com/articles/2011/09/20/retemplating-in-blend.aspx"&gt;tutorial&lt;/a&gt; to learn more.&lt;/p&gt; &lt;p&gt;So now I have a header bar with buttons that change colour when the corresponding page is selected. Where next?&lt;/p&gt; &lt;h4&gt;Textured Backgrounds&lt;/h4&gt; &lt;p&gt;Well, that page background could do with spicing up. The Photoshop design has a nice textured background, which I extracted to a PNG file that Silverlight would understand by hiding every layer except the background, then using Photoshop’s “Save for Web &amp;amp; Devices” feature. &lt;/p&gt; &lt;p&gt;The thing about textured backgrounds is that you do want them to cover the whole of the page background, which means tiling the texture to fill all the space. WPF makes this easy with its ImageBrush, which has a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.tilemode.aspx"&gt;TileMode&lt;/a&gt; property, which, when set to a value other than None, automatically repeats the image over the whole area to be painted by the brush. Silverlight has ImageBrushes, but they don’t support tiling out of the box. Fortunately, Phil Middlemiss has supplied what is lacking in the form of the &lt;a href="http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html"&gt;TiledBGControl&lt;/a&gt; which does exactly what I need – you should take a look: it makes clever use of Silverlight’s pixel shader effects.&lt;/p&gt; &lt;p&gt;This is what we’ve got so far. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_10.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_4.png" width="600" height="334"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;The Index Editor Page, Before and After&lt;/h4&gt; &lt;p&gt;Here are a couple of other pages I’ve beautified. First, the Index Editor page, as it was before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_12.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_5.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And now:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_14.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_6.png" width="600" height="365"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Again, it was a challenge knowing where to apply my beautician’s brush first. I settled on adding the header bar at the top, and I then realised it could double up as a toolbar. Originally the page had no header at all, but by having a bread-crumb bar in the header it helps to give the user a bit more context when they’re looking at the page, as well as making it easier to navigate around.&lt;/p&gt; &lt;h4&gt;Inspiration and Icons&lt;/h4&gt; &lt;p&gt;Since my graphic-design skills are so underdeveloped, I borrow ideas shamelessly wherever I find something that fits. You may recognise the styling of the toolbar buttons in the Index page header bar as being remarkably similar to the ones on the Google Chrome toolbar. Yes – Expression Blend’s Gradient dropper does work on live applications too! Two places to check out if you find yourself short on inspiration are &lt;a href="http://quince.infragistics.com/"&gt;Quince&lt;/a&gt; and &lt;a href="http://patterntap.com/"&gt;Pattern Tab&lt;/a&gt; which both catalogue examples of user interface and user experience design from across the web. Pattern Tab especially has myriad examples of beautiful UIs.&lt;/p&gt; &lt;p&gt;In the past I’ve struggled to find icons for my projects, but I’ve recently discovered two great sources: &lt;a href="http://www.iconfinder.com/"&gt;IconFinder.com&lt;/a&gt; and &lt;a href="http://www.iconarchive.com/"&gt;IconArchive.com&lt;/a&gt;. Both have excellent search facilities (which is often what’s missing from the commercial collections you buy and download to your machine in a whacking great zip file), and are careful to call out the license attached to each icon. A surprisingly large number are licensed so that they can be used without charge in commercial products.&lt;/p&gt; &lt;h4&gt;A XAML Tip&lt;/h4&gt; &lt;p&gt;The nice thing about styling an application is that it gets easier with every page you complete. Once you’ve settled on a look for a particular kind of element, you can repeat that look on every page. Silverlight’s support for Styles and Resources makes this very easy. And I have a tip that can make it easier still. &lt;/p&gt; &lt;p&gt;I put all my styles into a single resource dictionary, Styles.xaml which I merge into my App.xaml resource dictionary. I then name all my Styles, Brushes, etc. using a hierarchical naming convention. So Styles all begin with “Style_”, Styles for Buttons would all begin “Style_Button”, and then would come the styles for different purposes: “Style_Button_Toolbar”, “Style_Button_Hero” (for those big red buttons in your app that the hero uses to save the world), etc.. The pay-off for using this convention comes when you’re hand-editing XAML and making use of Resharper’s XAML intellisense. Type “{StaticResource Style_[ControlType]” and Resharper instantly presents you with a list of all the styles that might apply.&lt;/p&gt; &lt;h4&gt;A Parting Screenshot&lt;/h4&gt; &lt;p&gt;To finish, here’s one more before and after comparison, this time of the Edit Document page. Before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_16.png"&gt;&lt;img style="display: inline" title="Edit Document Page - Before" alt="Edit Document Page - Before" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_7.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And after:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_20.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_9.png" width="600" height="362"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can begin to sense the benefit of using a consistent set of styles, as it brings a harmonious feel to the whole application.&lt;/p&gt; &lt;p&gt;I hope you’ve enjoyed this whistle-stop tour of the Raven Studio beautification process. Remember that all the code is available on &lt;a href="https://github.com/ravendb/studio"&gt;GitHub&lt;/a&gt;. We’d love to hear what you think.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/NMPgSjKQPZs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/NMPgSjKQPZs/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</guid><pubDate>Mon, 24 Oct 2011 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</feedburner:origLink></item><item><title>XAML Magic: Turning an Ugly Silverlight Duckling into a Beautiful Photoshopped Swan</title><description>&lt;blockquote&gt; &lt;p&gt;This is a guest post by &lt;a href="http://blog.functionalfun.net"&gt;Samuel Jack&lt;/a&gt;, who had done a lot of work on the new UI for RavenDB.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Three weeks ago Ayende put out a request for &lt;a href="http://ayende.com/blog/111617/looking-for-a-xaml-expert"&gt;help in turning an ugly duckling into a beautiful swan&lt;/a&gt;, and I, rather nervously, signed up for the job. The ugly duckling in question was Raven Studio, the Silverlight-based management UI for Raven Db. The nerves were a result of doubting that my limited graphic design skills were up to the job. But when Ayende assured me that he had a proto-type swan in the form of a Photoshop design, drawn up by a bona-fide, turtle-neck-wearing designer, they were calmed. Marginally.&lt;/p&gt; &lt;p&gt;Because the design Ayende had was for the new-look RavenDb website. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_2.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb.png" width="600" height="457"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;He wanted me to take the look and feel and transfer it to the Silverlight Raven Studio application. Which, when he handed it over to me, looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_4.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_1.png" width="600" height="440"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ahh! Where to start?&lt;/p&gt; &lt;h4&gt;Photoshop for Developer Dummies&lt;/h4&gt; &lt;p&gt;To ease myself in, I got started by simply trying to imitate parts of the Photoshop design in XAML, beginning with the header bar at the very top of the page. Not being a designer myself, I’m rather like a duck out of water when it comes to Photoshop, but I’ve at least got the basics sussed.&lt;/p&gt; &lt;p&gt;The thing to understand is that designers construct Photoshop images like onions, layer upon layer, sometimes eye-watering in complexity, and to reproduce the design, you have to peel down through the layers. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_8.png"&gt;&lt;img style="display: inline; float: left" title="Photoshop Layer Basics" alt="Photoshop Layer Basics" align="left" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_3.png" width="450" height="241"&gt;&lt;/a&gt;First go to Photoshop’s Layers pane, and make sure all the layers are unlocked. This allows the Move Layer tool to come into play, not to move layers, but identify layers by selecting them in the Layers pane when you click the corresponding part of the image. Once you’ve identified a layer, Alt-Click it, and all other layers in the image will be hidden, allowing you to figure out exactly how the thing should look.&lt;/p&gt; &lt;p&gt;Mostly when I’m paring down Photoshop layers I’m looking to isolate them so that I can figure out the colour gradients they use. You could, of course, navigate your way through Photoshop’s dialogs to read off the exact RGB values. Or, if you can get the layer on its lonesome, you can use Expression Blend’s Gradient Dropper tool. &lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_2.png"&gt;&lt;img style="margin: 5px 0px; display: inline; float: right" title="GradientEyeDropper" alt="GradientEyeDropper" align="right" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_thumb.png" width="240" height="221"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a brilliant little timesaver. In the Blend Property pane, select the Brush property of your choice, put it into Gradient mode, click the Gradient Dropper tool, then drag over any area on screen, and Blend will reproduce the gradient under the cursor in XAML form.&lt;/p&gt; &lt;p&gt;After all that, I have the first feather of the new swan: a header bar matching the Photoshop design. Well, the background of the header bar. It needs fleshing out with some buttons.&lt;/p&gt; &lt;h4&gt;Let it Live: Control Templates and Visual States&lt;/h4&gt; &lt;p&gt;Silverlight, following WPF, has the concept of look-less controls. That is, the Controls (take Button as an example) manage their behaviour (Buttons respond to mouse clicks by executing commands) but don’t define how they are rendered on screen. That is left to the control’s &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_basics"&gt;Style&lt;/a&gt;, and specifically its &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_controltemplates"&gt;ControlTemplate&lt;/a&gt;. The ControlTemplate defines the visual tree of all the UI elements needed to present the control and make it look snazzy. With a little patience, some assistance from Expression Blend, and plenty of application of the Gradient Dropper tool, it’s possible to take the built-in controls and make them look and feel just how the designer ordered.&lt;/p&gt; &lt;p&gt;I wanted Buttons that look like those in the header bar of the Photoshop design, but when the corresponding page is selected, they should change to have a background gradient with colours like the RavenDb logo.&lt;/p&gt; &lt;p&gt;When restyling a Control, it’s best to start by modifying the existing style. This way you can be sure you won’t miss an aspect of the control’s behaviour that you might otherwise forget. Blend makes this easy by giving you the option of editing a copy of the Control’s current ControlTemplate (right-click on it in the Objects and Timeline View, then select Edit Template &amp;gt; Edit a Copy). There are occasions when that little trick has failed, and I’ve ended up with an empty control template. But MSDN has come through for me then: it has a whole section containing the &lt;a href="http://msdn.microsoft.com/en-us/library/cc278075(v=VS.95).aspx"&gt;default Styles and Control Templates for all the built-in controls&lt;/a&gt;, like this one for &lt;a href="http://msdn.microsoft.com/en-us/library/cc278069(v=VS.95).aspx"&gt;Button&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Part of the ControlTemplate defines how the control looks in its various states, when the mouse is over it, when it has focus, or when it is selected, for example. The Control itself is responsible for indicating when it has entered each state. As a designer, it’s your job to specify Storyboards that are activated each time particular states are entered. Each Storyboard can animate whichever properties it likes to achieve the desired effect – in my Buttons, for example, I animate the opacity property of a Border element to fade in a coloured background indicating that it is selected. All this is overseen by the VisualStateManager, of which, more &lt;a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspx"&gt;here&lt;/a&gt;. Naturally, Expression Blend has great editing support for visual states. Read John Papa’s &lt;a href="http://visualstudiomagazine.com/articles/2011/09/20/retemplating-in-blend.aspx"&gt;tutorial&lt;/a&gt; to learn more.&lt;/p&gt; &lt;p&gt;So now I have a header bar with buttons that change colour when the corresponding page is selected. Where next?&lt;/p&gt; &lt;h4&gt;Textured Backgrounds&lt;/h4&gt; &lt;p&gt;Well, that page background could do with spicing up. The Photoshop design has a nice textured background, which I extracted to a PNG file that Silverlight would understand by hiding every layer except the background, then using Photoshop’s “Save for Web &amp;amp; Devices” feature. &lt;/p&gt; &lt;p&gt;The thing about textured backgrounds is that you do want them to cover the whole of the page background, which means tiling the texture to fill all the space. WPF makes this easy with its ImageBrush, which has a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.tilemode.aspx"&gt;TileMode&lt;/a&gt; property, which, when set to a value other than None, automatically repeats the image over the whole area to be painted by the brush. Silverlight has ImageBrushes, but they don’t support tiling out of the box. Fortunately, Phil Middlemiss has supplied what is lacking in the form of the &lt;a href="http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html"&gt;TiledBGControl&lt;/a&gt; which does exactly what I need – you should take a look: it makes clever use of Silverlight’s pixel shader effects.&lt;/p&gt; &lt;p&gt;This is what we’ve got so far. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_10.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_4.png" width="600" height="334"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;The Index Editor Page, Before and After&lt;/h4&gt; &lt;p&gt;Here are a couple of other pages I’ve beautified. First, the Index Editor page, as it was before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_12.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_5.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And now:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_14.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_6.png" width="600" height="365"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Again, it was a challenge knowing where to apply my beautician’s brush first. I settled on adding the header bar at the top, and I then realised it could double up as a toolbar. Originally the page had no header at all, but by having a bread-crumb bar in the header it helps to give the user a bit more context when they’re looking at the page, as well as making it easier to navigate around.&lt;/p&gt; &lt;h4&gt;Inspiration and Icons&lt;/h4&gt; &lt;p&gt;Since my graphic-design skills are so underdeveloped, I borrow ideas shamelessly wherever I find something that fits. You may recognise the styling of the toolbar buttons in the Index page header bar as being remarkably similar to the ones on the Google Chrome toolbar. Yes – Expression Blend’s Gradient dropper does work on live applications too! Two places to check out if you find yourself short on inspiration are &lt;a href="http://quince.infragistics.com/"&gt;Quince&lt;/a&gt; and &lt;a href="http://patterntap.com/"&gt;Pattern Tab&lt;/a&gt; which both catalogue examples of user interface and user experience design from across the web. Pattern Tab especially has myriad examples of beautiful UIs.&lt;/p&gt; &lt;p&gt;In the past I’ve struggled to find icons for my projects, but I’ve recently discovered two great sources: &lt;a href="http://www.iconfinder.com/"&gt;IconFinder.com&lt;/a&gt; and &lt;a href="http://www.iconarchive.com/"&gt;IconArchive.com&lt;/a&gt;. Both have excellent search facilities (which is often what’s missing from the commercial collections you buy and download to your machine in a whacking great zip file), and are careful to call out the license attached to each icon. A surprisingly large number are licensed so that they can be used without charge in commercial products.&lt;/p&gt; &lt;h4&gt;A XAML Tip&lt;/h4&gt; &lt;p&gt;The nice thing about styling an application is that it gets easier with every page you complete. Once you’ve settled on a look for a particular kind of element, you can repeat that look on every page. Silverlight’s support for Styles and Resources makes this very easy. And I have a tip that can make it easier still. &lt;/p&gt; &lt;p&gt;I put all my styles into a single resource dictionary, Styles.xaml which I merge into my App.xaml resource dictionary. I then name all my Styles, Brushes, etc. using a hierarchical naming convention. So Styles all begin with “Style_”, Styles for Buttons would all begin “Style_Button”, and then would come the styles for different purposes: “Style_Button_Toolbar”, “Style_Button_Hero” (for those big red buttons in your app that the hero uses to save the world), etc.. The pay-off for using this convention comes when you’re hand-editing XAML and making use of Resharper’s XAML intellisense. Type “{StaticResource Style_[ControlType]” and Resharper instantly presents you with a list of all the styles that might apply.&lt;/p&gt; &lt;h4&gt;A Parting Screenshot&lt;/h4&gt; &lt;p&gt;To finish, here’s one more before and after comparison, this time of the Edit Document page. Before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_16.png"&gt;&lt;img style="display: inline" title="Edit Document Page - Before" alt="Edit Document Page - Before" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_7.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And after:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_20.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_9.png" width="600" height="362"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can begin to sense the benefit of using a consistent set of styles, as it brings a harmonious feel to the whole application.&lt;/p&gt; &lt;p&gt;I hope you’ve enjoyed this whistle-stop tour of the Raven Studio beautification process. Remember that all the code is available on &lt;a href="https://github.com/ravendb/studio"&gt;GitHub&lt;/a&gt;. We’d love to hear what you think.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/NMPgSjKQPZs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/NMPgSjKQPZs/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</guid><pubDate>Mon, 24 Oct 2011 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</feedburner:origLink></item><item><title>XAML Magic: Turning an Ugly Silverlight Duckling into a Beautiful Photoshopped Swan</title><description>&lt;blockquote&gt; &lt;p&gt;This is a guest post by &lt;a href="http://blog.functionalfun.net"&gt;Samuel Jack&lt;/a&gt;, who had done a lot of work on the new UI for RavenDB.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Three weeks ago Ayende put out a request for &lt;a href="http://ayende.com/blog/111617/looking-for-a-xaml-expert"&gt;help in turning an ugly duckling into a beautiful swan&lt;/a&gt;, and I, rather nervously, signed up for the job. The ugly duckling in question was Raven Studio, the Silverlight-based management UI for Raven Db. The nerves were a result of doubting that my limited graphic design skills were up to the job. But when Ayende assured me that he had a proto-type swan in the form of a Photoshop design, drawn up by a bona-fide, turtle-neck-wearing designer, they were calmed. Marginally.&lt;/p&gt; &lt;p&gt;Because the design Ayende had was for the new-look RavenDb website. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_2.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb.png" width="600" height="457"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;He wanted me to take the look and feel and transfer it to the Silverlight Raven Studio application. Which, when he handed it over to me, looked like this:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_4.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_1.png" width="600" height="440"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Ahh! Where to start?&lt;/p&gt; &lt;h4&gt;Photoshop for Developer Dummies&lt;/h4&gt; &lt;p&gt;To ease myself in, I got started by simply trying to imitate parts of the Photoshop design in XAML, beginning with the header bar at the very top of the page. Not being a designer myself, I’m rather like a duck out of water when it comes to Photoshop, but I’ve at least got the basics sussed.&lt;/p&gt; &lt;p&gt;The thing to understand is that designers construct Photoshop images like onions, layer upon layer, sometimes eye-watering in complexity, and to reproduce the design, you have to peel down through the layers. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_8.png"&gt;&lt;img style="display: inline; float: left" title="Photoshop Layer Basics" alt="Photoshop Layer Basics" align="left" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_3.png" width="450" height="241"&gt;&lt;/a&gt;First go to Photoshop’s Layers pane, and make sure all the layers are unlocked. This allows the Move Layer tool to come into play, not to move layers, but identify layers by selecting them in the Layers pane when you click the corresponding part of the image. Once you’ve identified a layer, Alt-Click it, and all other layers in the image will be hidden, allowing you to figure out exactly how the thing should look.&lt;/p&gt; &lt;p&gt;Mostly when I’m paring down Photoshop layers I’m looking to isolate them so that I can figure out the colour gradients they use. You could, of course, navigate your way through Photoshop’s dialogs to read off the exact RGB values. Or, if you can get the layer on its lonesome, you can use Expression Blend’s Gradient Dropper tool. &lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_2.png"&gt;&lt;img style="margin: 5px 0px; display: inline; float: right" title="GradientEyeDropper" alt="GradientEyeDropper" align="right" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/GradientEyeDropper_thumb.png" width="240" height="221"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;This is a brilliant little timesaver. In the Blend Property pane, select the Brush property of your choice, put it into Gradient mode, click the Gradient Dropper tool, then drag over any area on screen, and Blend will reproduce the gradient under the cursor in XAML form.&lt;/p&gt; &lt;p&gt;After all that, I have the first feather of the new swan: a header bar matching the Photoshop design. Well, the background of the header bar. It needs fleshing out with some buttons.&lt;/p&gt; &lt;h4&gt;Let it Live: Control Templates and Visual States&lt;/h4&gt; &lt;p&gt;Silverlight, following WPF, has the concept of look-less controls. That is, the Controls (take Button as an example) manage their behaviour (Buttons respond to mouse clicks by executing commands) but don’t define how they are rendered on screen. That is left to the control’s &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_basics"&gt;Style&lt;/a&gt;, and specifically its &lt;a href="http://msdn.microsoft.com/en-us/library/ms745683.aspx#styling_controltemplates"&gt;ControlTemplate&lt;/a&gt;. The ControlTemplate defines the visual tree of all the UI elements needed to present the control and make it look snazzy. With a little patience, some assistance from Expression Blend, and plenty of application of the Gradient Dropper tool, it’s possible to take the built-in controls and make them look and feel just how the designer ordered.&lt;/p&gt; &lt;p&gt;I wanted Buttons that look like those in the header bar of the Photoshop design, but when the corresponding page is selected, they should change to have a background gradient with colours like the RavenDb logo.&lt;/p&gt; &lt;p&gt;When restyling a Control, it’s best to start by modifying the existing style. This way you can be sure you won’t miss an aspect of the control’s behaviour that you might otherwise forget. Blend makes this easy by giving you the option of editing a copy of the Control’s current ControlTemplate (right-click on it in the Objects and Timeline View, then select Edit Template &amp;gt; Edit a Copy). There are occasions when that little trick has failed, and I’ve ended up with an empty control template. But MSDN has come through for me then: it has a whole section containing the &lt;a href="http://msdn.microsoft.com/en-us/library/cc278075(v=VS.95).aspx"&gt;default Styles and Control Templates for all the built-in controls&lt;/a&gt;, like this one for &lt;a href="http://msdn.microsoft.com/en-us/library/cc278069(v=VS.95).aspx"&gt;Button&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Part of the ControlTemplate defines how the control looks in its various states, when the mouse is over it, when it has focus, or when it is selected, for example. The Control itself is responsible for indicating when it has entered each state. As a designer, it’s your job to specify Storyboards that are activated each time particular states are entered. Each Storyboard can animate whichever properties it likes to achieve the desired effect – in my Buttons, for example, I animate the opacity property of a Border element to fade in a coloured background indicating that it is selected. All this is overseen by the VisualStateManager, of which, more &lt;a href="http://windowsclient.net/wpf/wpf35/wpf-35sp1-toolkit-visual-state-manager-overview.aspx"&gt;here&lt;/a&gt;. Naturally, Expression Blend has great editing support for visual states. Read John Papa’s &lt;a href="http://visualstudiomagazine.com/articles/2011/09/20/retemplating-in-blend.aspx"&gt;tutorial&lt;/a&gt; to learn more.&lt;/p&gt; &lt;p&gt;So now I have a header bar with buttons that change colour when the corresponding page is selected. Where next?&lt;/p&gt; &lt;h4&gt;Textured Backgrounds&lt;/h4&gt; &lt;p&gt;Well, that page background could do with spicing up. The Photoshop design has a nice textured background, which I extracted to a PNG file that Silverlight would understand by hiding every layer except the background, then using Photoshop’s “Save for Web &amp;amp; Devices” feature. &lt;/p&gt; &lt;p&gt;The thing about textured backgrounds is that you do want them to cover the whole of the page background, which means tiling the texture to fill all the space. WPF makes this easy with its ImageBrush, which has a &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.tilebrush.tilemode.aspx"&gt;TileMode&lt;/a&gt; property, which, when set to a value other than None, automatically repeats the image over the whole area to be painted by the brush. Silverlight has ImageBrushes, but they don’t support tiling out of the box. Fortunately, Phil Middlemiss has supplied what is lacking in the form of the &lt;a href="http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html"&gt;TiledBGControl&lt;/a&gt; which does exactly what I need – you should take a look: it makes clever use of Silverlight’s pixel shader effects.&lt;/p&gt; &lt;p&gt;This is what we’ve got so far. &lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_10.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_4.png" width="600" height="334"&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;The Index Editor Page, Before and After&lt;/h4&gt; &lt;p&gt;Here are a couple of other pages I’ve beautified. First, the Index Editor page, as it was before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_12.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_5.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And now:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_14.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_6.png" width="600" height="365"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Again, it was a challenge knowing where to apply my beautician’s brush first. I settled on adding the header bar at the top, and I then realised it could double up as a toolbar. Originally the page had no header at all, but by having a bread-crumb bar in the header it helps to give the user a bit more context when they’re looking at the page, as well as making it easier to navigate around.&lt;/p&gt; &lt;h4&gt;Inspiration and Icons&lt;/h4&gt; &lt;p&gt;Since my graphic-design skills are so underdeveloped, I borrow ideas shamelessly wherever I find something that fits. You may recognise the styling of the toolbar buttons in the Index page header bar as being remarkably similar to the ones on the Google Chrome toolbar. Yes – Expression Blend’s Gradient dropper does work on live applications too! Two places to check out if you find yourself short on inspiration are &lt;a href="http://quince.infragistics.com/"&gt;Quince&lt;/a&gt; and &lt;a href="http://patterntap.com/"&gt;Pattern Tab&lt;/a&gt; which both catalogue examples of user interface and user experience design from across the web. Pattern Tab especially has myriad examples of beautiful UIs.&lt;/p&gt; &lt;p&gt;In the past I’ve struggled to find icons for my projects, but I’ve recently discovered two great sources: &lt;a href="http://www.iconfinder.com/"&gt;IconFinder.com&lt;/a&gt; and &lt;a href="http://www.iconarchive.com/"&gt;IconArchive.com&lt;/a&gt;. Both have excellent search facilities (which is often what’s missing from the commercial collections you buy and download to your machine in a whacking great zip file), and are careful to call out the license attached to each icon. A surprisingly large number are licensed so that they can be used without charge in commercial products.&lt;/p&gt; &lt;h4&gt;A XAML Tip&lt;/h4&gt; &lt;p&gt;The nice thing about styling an application is that it gets easier with every page you complete. Once you’ve settled on a look for a particular kind of element, you can repeat that look on every page. Silverlight’s support for Styles and Resources makes this very easy. And I have a tip that can make it easier still. &lt;/p&gt; &lt;p&gt;I put all my styles into a single resource dictionary, Styles.xaml which I merge into my App.xaml resource dictionary. I then name all my Styles, Brushes, etc. using a hierarchical naming convention. So Styles all begin with “Style_”, Styles for Buttons would all begin “Style_Button”, and then would come the styles for different purposes: “Style_Button_Toolbar”, “Style_Button_Hero” (for those big red buttons in your app that the hero uses to save the world), etc.. The pay-off for using this convention comes when you’re hand-editing XAML and making use of Resharper’s XAML intellisense. Type “{StaticResource Style_[ControlType]” and Resharper instantly presents you with a list of all the styles that might apply.&lt;/p&gt; &lt;h4&gt;A Parting Screenshot&lt;/h4&gt; &lt;p&gt;To finish, here’s one more before and after comparison, this time of the Edit Document page. Before:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_16.png"&gt;&lt;img style="display: inline" title="Edit Document Page - Before" alt="Edit Document Page - Before" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_7.png" width="600" height="340"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And after:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_20.png"&gt;&lt;img style="display: inline" title="image" alt="image" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/4c8d5ac8e3b0_A71A/image_thumb_9.png" width="600" height="362"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;You can begin to sense the benefit of using a consistent set of styles, as it brings a harmonious feel to the whole application.&lt;/p&gt; &lt;p&gt;I hope you’ve enjoyed this whistle-stop tour of the Raven Studio beautification process. Remember that all the code is available on &lt;a href="https://github.com/ravendb/studio"&gt;GitHub&lt;/a&gt;. We’d love to hear what you think.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/NMPgSjKQPZs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/NMPgSjKQPZs/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</guid><pubDate>Mon, 24 Oct 2011 10:00:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/10241/xaml-magic-turning-an-ugly-silverlight-duckling-into-a-beautiful-photoshopped-swan?key=32068780-c3a0-458c-b74d-d5911d0d3024</feedburner:origLink></item><item><title>Sneak peek at the new RavenDB Studio</title><description>&lt;p&gt;We started to develop the next generation of RavenDB Studio and I wanted to share a screenshot of first take of the new UI in order to gather some feedback:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/First-take-of_DD20/RavenDB-UI_1.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="RavenDB-UI" border="0" alt="RavenDB-UI" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/First-take-of_DD20/RavenDB-UI_thumb_1.png" width="1016" height="710"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The main goals of the new UI are:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Responsiveness.&lt;/strong&gt; You can’t see this in this picture but the UI that we play with now is &lt;em&gt;very&lt;/em&gt; responsive.&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Easy to use.&lt;/strong&gt; The UI should be simple and very easy to use.&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Easy to understand.&lt;/strong&gt; This goal is to create a project that is very easy to contribute to. So far, we had very little contributions to the Studio, no doubt because the current version is quite complex. We are trying to make it very easy to understand and work with the new studio, so if you have a problem or want a new feature, it would be trivial to add and contribute.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/3TbEfL-AbgA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/3TbEfL-AbgA/sneak-peek-at-the-new-ravendb-studio</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/9217/sneak-peek-at-the-new-ravendb-studio?key=e3043817-c1b9-4c54-8482-4e1b0bcd7e1b</guid><pubDate>Sun, 02 Oct 2011 14:24:46 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/9217/sneak-peek-at-the-new-ravendb-studio?key=e3043817-c1b9-4c54-8482-4e1b0bcd7e1b</feedburner:origLink></item><item><title>Sneak peek at the new RavenDB Studio</title><description>&lt;p&gt;We started to develop the next generation of RavenDB Studio and I wanted to share a screenshot of first take of the new UI in order to gather some feedback:&lt;/p&gt; &lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/First-take-of_DD20/RavenDB-UI_1.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="RavenDB-UI" border="0" alt="RavenDB-UI" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/First-take-of_DD20/RavenDB-UI_thumb_1.png" width="1016" height="710"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The main goals of the new UI are:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;&lt;strong&gt;Responsiveness.&lt;/strong&gt; You can’t see this in this picture but the UI that we play with now is &lt;em&gt;very&lt;/em&gt; responsive.&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Easy to use.&lt;/strong&gt; The UI should be simple and very easy to use.&lt;/li&gt; &lt;li&gt;&lt;strong&gt;Easy to understand.&lt;/strong&gt; This goal is to create a project that is very easy to contribute to. So far, we had very little contributions to the Studio, no doubt because the current version is quite complex. We are trying to make it very easy to understand and work with the new studio, so if you have a problem or want a new feature, it would be trivial to add and contribute.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/3TbEfL-AbgA" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/3TbEfL-AbgA/sneak-peek-at-the-new-ravendb-studio</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/9217/sneak-peek-at-the-new-ravendb-studio?key=e3043817-c1b9-4c54-8482-4e1b0bcd7e1b</guid><pubDate>Sun, 02 Oct 2011 14:24:46 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/9217/sneak-peek-at-the-new-ravendb-studio?key=e3043817-c1b9-4c54-8482-4e1b0bcd7e1b</feedburner:origLink></item><item><title>RavenDB Webinar #1 now available on YouTube</title><description>&lt;p&gt;The first ever RavenDB webinar aired last week, Thursday the 8th, and it was a great success. We announced it only about 12 hours in advance, yet 260+ people registered. Unfortunately the software we were using only allowed 100 people in – our apologies for all of you who wanted to participate but couldn’t get in, or heard of it too late.&lt;/p&gt; &lt;p&gt;We have now uploaded the recording to our YouTube channel here, and you can watch it from there. Embedded here is the first part:&lt;/p&gt; &lt;p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:5fed0a60-e7ba-4a1d-ab8b-b2cf340655c9" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;object width="448" height="252"&gt;&lt;param name="movie" value="http://www.youtube.com/v/PGz9GokDkkg?hl=en&amp;amp;hd=1"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/PGz9GokDkkg?hl=en&amp;amp;hd=1" type="application/x-shockwave-flash" width="448" height="252"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;The other parts are available from our YouTube channel: &lt;a href="http://www.youtube.com/user/HibernatingRhinos"&gt;www.youtube.com/user/HibernatingRhinos&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;We had a second webinar last Friday, and had a very good Q&amp;amp;A session during it. Unfortunately _someone_ forgot to press the “Record” button, and there we are all left with no recording…&lt;/p&gt; &lt;p&gt;&lt;u&gt;RavenDB webinars are here to stay&lt;/u&gt;. We are still formulating our plans for future webcasts – both in terms of a format and topics. The general idea is that whenever there will be enough demand, we will do a webcast on a specific topic, or just a Q&amp;amp;A session. Ideally we would like to have a bi-weekly session, and by the time we settle on a format you can expect many more spontaneous sessions like we had last week…&lt;/p&gt; &lt;p&gt;This is why we would really like to hear back from you. What are you looking for to have, when, in what format. Any other feedback – here or in the RavenDB mailing list – is definitely welcome.&lt;/p&gt; &lt;p&gt;See you all in our next webinars…&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/U3r8XPwWWAw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/U3r8XPwWWAw/ravendb-webinar-1-now-available-on-youtube</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/8193/ravendb-webinar-1-now-available-on-youtube?key=06ee1015-247d-4dc0-8268-0db2a3ce8d00</guid><pubDate>Sun, 11 Sep 2011 04:58:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/8193/ravendb-webinar-1-now-available-on-youtube?key=06ee1015-247d-4dc0-8268-0db2a3ce8d00</feedburner:origLink></item><item><title>RavenDB Webinar #1 now available on YouTube</title><description>&lt;p&gt;The first ever RavenDB webinar aired last week, Thursday the 8th, and it was a great success. We announced it only about 12 hours in advance, yet 260+ people registered. Unfortunately the software we were using only allowed 100 people in – our apologies for all of you who wanted to participate but couldn’t get in, or heard of it too late.&lt;/p&gt; &lt;p&gt;We have now uploaded the recording to our YouTube channel here, and you can watch it from there. Embedded here is the first part:&lt;/p&gt; &lt;p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:5fed0a60-e7ba-4a1d-ab8b-b2cf340655c9" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;object width="448" height="252"&gt;&lt;param name="movie" value="http://www.youtube.com/v/PGz9GokDkkg?hl=en&amp;amp;hd=1"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/PGz9GokDkkg?hl=en&amp;amp;hd=1" type="application/x-shockwave-flash" width="448" height="252"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/div&gt;&lt;/div&gt;&lt;/p&gt; &lt;p&gt;The other parts are available from our YouTube channel: &lt;a href="http://www.youtube.com/user/HibernatingRhinos"&gt;www.youtube.com/user/HibernatingRhinos&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;We had a second webinar last Friday, and had a very good Q&amp;amp;A session during it. Unfortunately _someone_ forgot to press the “Record” button, and there we are all left with no recording…&lt;/p&gt; &lt;p&gt;&lt;u&gt;RavenDB webinars are here to stay&lt;/u&gt;. We are still formulating our plans for future webcasts – both in terms of a format and topics. The general idea is that whenever there will be enough demand, we will do a webcast on a specific topic, or just a Q&amp;amp;A session. Ideally we would like to have a bi-weekly session, and by the time we settle on a format you can expect many more spontaneous sessions like we had last week…&lt;/p&gt; &lt;p&gt;This is why we would really like to hear back from you. What are you looking for to have, when, in what format. Any other feedback – here or in the RavenDB mailing list – is definitely welcome.&lt;/p&gt; &lt;p&gt;See you all in our next webinars…&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/U3r8XPwWWAw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/U3r8XPwWWAw/ravendb-webinar-1-now-available-on-youtube</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/8193/ravendb-webinar-1-now-available-on-youtube?key=06ee1015-247d-4dc0-8268-0db2a3ce8d00</guid><pubDate>Sun, 11 Sep 2011 04:58:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/8193/ravendb-webinar-1-now-available-on-youtube?key=06ee1015-247d-4dc0-8268-0db2a3ce8d00</feedburner:origLink></item><item><title>Entity Framework Profiler supports for LinqPAD</title><description>&lt;p&gt;If you’re using &lt;a href="http://www.linqpad.net/" target="_blank"&gt;LinqPAD&lt;/a&gt; and wants to profile your Entity Framework usage with the &lt;a href="http://efprof.com/" target="_blank"&gt;Entity Framework Profiler&lt;/a&gt;, you can use the following snippet of code in order to achieve that:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
{
    HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
    Blogs.Take(50).Dump();
}&lt;/pre&gt;
&lt;p&gt;Please make sure to use the "C# Program" option from the "language" ComboBox, and that’s it. You can now see the the profiling data in the &lt;a href="http://efprof.com/" target="_blank"&gt;Entity Framework Profiler&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/Entity-Framework-support_B683/LinqPAD.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="LinqPAD" border="0" alt="LinqPAD" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/Entity-Framework-support_B683/LinqPAD_thumb.png" width="1049" height="415"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/ms7tYFwi7BI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/ms7tYFwi7BI/entity-framework-profiler-supports-for-linqpad</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/7169/entity-framework-profiler-supports-for-linqpad?key=ab73734f-3519-4ce8-80c0-b6dacad01ced</guid><pubDate>Fri, 29 Jul 2011 07:33:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/7169/entity-framework-profiler-supports-for-linqpad?key=ab73734f-3519-4ce8-80c0-b6dacad01ced</feedburner:origLink></item><item><title>Entity Framework Profiler supports for LinqPAD</title><description>&lt;p&gt;If you’re using &lt;a href="http://www.linqpad.net/" target="_blank"&gt;LinqPAD&lt;/a&gt; and wants to profile your Entity Framework usage with the &lt;a href="http://efprof.com/" target="_blank"&gt;Entity Framework Profiler&lt;/a&gt;, you can use the following snippet of code in order to achieve that:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
{
    HibernatingRhinos.Profiler.Appender.EntityFramework.EntityFrameworkProfiler.Initialize();
    Blogs.Take(50).Dump();
}&lt;/pre&gt;
&lt;p&gt;Please make sure to use the "C# Program" option from the "language" ComboBox, and that’s it. You can now see the the profiling data in the &lt;a href="http://efprof.com/" target="_blank"&gt;Entity Framework Profiler&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/Entity-Framework-support_B683/LinqPAD.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="LinqPAD" border="0" alt="LinqPAD" src="http://blog.hibernatingrhinos.com/Images/Windows-Live-Writer/Entity-Framework-support_B683/LinqPAD_thumb.png" width="1049" height="415"&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/HibernatingRhinos/~4/ms7tYFwi7BI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/HibernatingRhinos/~3/ms7tYFwi7BI/entity-framework-profiler-supports-for-linqpad</link><guid isPermaLink="false">http://blog.hibernatingrhinos.com/7169/entity-framework-profiler-supports-for-linqpad?key=ab73734f-3519-4ce8-80c0-b6dacad01ced</guid><pubDate>Fri, 29 Jul 2011 07:33:00 GMT</pubDate><feedburner:origLink>http://blog.hibernatingrhinos.com/7169/entity-framework-profiler-supports-for-linqpad?key=ab73734f-3519-4ce8-80c0-b6dacad01ced</feedburner:origLink></item></channel></rss>

