<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Essential XAML : Design, Thoughts and Ideas</title><link>http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/Design/Thoughts+and+Ideas/default.aspx</link><description>Tags: Design, Thoughts and Ideas</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>UI Virtualization vs. Data Virtualization (Part 1)</title><link>http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/09/07/ui-virtualization-vs-data-virtualization.aspx</link><pubDate>Mon, 07 Sep 2009 04:42:00 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:398462</guid><dc:creator>Tomer Shamam</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/tomershamam/rsscomments.aspx?PostID=398462</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/tomershamam/commentapi.aspx?PostID=398462</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/09/07/ui-virtualization-vs-data-virtualization.aspx#comments</comments><description>&lt;p align="justify"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/10/01/ui-virtualization-vs-data-virtualization-part-2.aspx"&gt;Part 2&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p align="justify"&gt;Being an LOB, composite applications infrastructure junky lately, I’ve been working around with several data-binding models and mechanisms to bind the data with the view, in a very efficient way of course. Sometime it was easy, and sometime it was not! I have had to find several workarounds to overcome both architectural and performance issues.&lt;/p&gt;
&lt;p align="justify"&gt;In this post I would like to concentrate on Data Virtualization, and to compare it with UI Virtualization, which are very similar, yet different aspects of the same problem.&lt;/p&gt;
&lt;p align="justify"&gt;After reading this post you&amp;#39;ll have an idea of what is Data Virtualization compared to UI Virtualization, and what it is good for.&lt;/p&gt;
&lt;p align="justify"&gt;&lt;strong&gt;UI Virtualization&lt;/strong&gt;&lt;/p&gt;
&lt;p align="justify"&gt;To understand what UI Virtualization is, lets say that you want to display a HUGE amount of data entries in a WPF &lt;em&gt;DataGrid&lt;/em&gt;, all at once. In such case, trying to bind a simple WPF DataGrid with, lets say, 100,000 or more items, you’ll have to wait one or two seconds for the initial binding.&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;partial&lt;/span&gt; &lt;span style="COLOR:blue;"&gt;class&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;Window1&lt;/span&gt; : &lt;span style="COLOR:#2b91af;"&gt;Window&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;{&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;public&lt;/span&gt; Window1()&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR:blue;"&gt;var&lt;/span&gt; hugeCollection = &lt;span style="COLOR:blue;"&gt;new&lt;/span&gt; &lt;span style="COLOR:#2b91af;"&gt;HugeCollection&lt;/span&gt;();&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataContext = hugeCollection;&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="MARGIN:0px;FONT-FAMILY:courier new;BACKGROUND:white;COLOR:black;FONT-SIZE:10pt;" align="justify"&gt;}&lt;/p&gt;
&lt;div align="justify"&gt;&lt;pre class="code"&gt;&lt;font size="2"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Window ...&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Grid&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;tk&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;DataGrid &lt;/span&gt;&lt;span style="COLOR:red;"&gt;ItemsSource&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Binding&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="COLOR:blue;"&gt;}&amp;quot; /&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Grid&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Window&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p align="justify"&gt;Well its really nothing!&lt;/p&gt;
&lt;p align="justify"&gt;Now lets change a little flag on the data grid.&lt;/p&gt;
&lt;div align="justify"&gt;&lt;pre class="code"&gt;&lt;span style="COLOR:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;tk&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;:&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;DataGrid &lt;/span&gt;&lt;span style="COLOR:red;"&gt;ItemsSource&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="COLOR:#a31515;"&gt;Binding&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="COLOR:red;"&gt;&lt;strong&gt;VirtualizingStackPanel.IsVirtualizing&lt;/strong&gt;&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;&lt;strong&gt;=&amp;quot;False&amp;quot;&lt;/strong&gt; /&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p align="justify"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;Now, before you run this app, if you use a lap-top (like me… ;), connect it to an AC power adapter first. Trust me, your laptop will need that.&lt;/p&gt;
&lt;p align="justify"&gt;As you can see, the CPU stuck on 100% and it takes eternity to see the data (I just had to kill the process).&lt;/p&gt;
&lt;p align="justify"&gt;What’s wrong? It’s only a little flag: &lt;span style="COLOR:red;"&gt;VirtualizingStackPanel.IsVirtualizing&lt;/span&gt;&lt;span style="COLOR:blue;"&gt;=&amp;quot;False&amp;quot;&lt;/span&gt;.&lt;/p&gt;
&lt;p align="justify"&gt;Well, it’s indeed a little flag that makes a big difference. If this flag is true (which is the default) it instructs the &lt;em&gt;VirtualizingStackPanel&lt;/em&gt; (which is the default layout panel in a &lt;em&gt;DataGrid&lt;/em&gt;, &lt;em&gt;ListView&lt;/em&gt;, &lt;em&gt;ListBox&lt;/em&gt; and other controls) to use UI virtualization. Means: don’t create data grid rows that are not visible to the user (in other words, are not in view). So this gives you a clue for what happened when we turned off this flag. We told &lt;em&gt;VisrtualizingStackPanel&lt;/em&gt; not to use UI Virtualization, hence the &lt;em&gt;DataGrid&lt;/em&gt; control tried to create and layout 100,000 rows! And this is a CPU killer as you saw.&lt;/p&gt;
&lt;p align="justify"&gt;&lt;strong&gt;Data Virtualization&lt;/strong&gt;&lt;/p&gt;
&lt;p align="justify"&gt;WPF internally implements UI Virtualization and it’s great. In the previous case, UI Virtualization is just fine. We’ve got 100,000 items loaded in memory, and all we’ve had to do is to bound them with the &lt;em&gt;DataGrid&lt;/em&gt;.&lt;/p&gt;
&lt;p align="justify"&gt;But what if each entry takes more than 1MB?&lt;/p&gt;
&lt;p align="justify"&gt;100,000 * 1MB = 97GB – Huston, we have a problem!&lt;/p&gt;
&lt;p align="justify"&gt;Well, the fast answer of course would be: Don’t load all items at once, instead use chunks. And this is exactly what Data Virtualization is!&lt;/p&gt;
&lt;p align="justify"&gt;Data Virtualization implementation raises several problems, and there is no out-of-the-box solution for Data Virtualization in WPF.&lt;/p&gt;
&lt;p align="justify"&gt;Well, first problem is: How do you fake scrollbars, so the user will think that it has all the data, and will be able to scroll?&lt;/p&gt;
&lt;p align="justify"&gt;Second problem: How do you filter, sort, group data that doesn’t exist?&lt;/p&gt;
&lt;p align="justify"&gt;Third problem: How do you search data (&lt;a href="http://blogs.microsoft.co.il/blogs/tomershamam/archive/2009/08/27/wpf-datagrid-search-and-highlight.aspx"&gt;like this search&lt;/a&gt;) that doesn’t exist?&lt;/p&gt;
&lt;p align="justify"&gt;These are all tough questions.&lt;/p&gt;
&lt;p align="justify"&gt;So what do you think? Do you have an easy way or acceptable solution to solve this problem?&lt;/p&gt;
&lt;p align="justify"&gt;Next post I’ll introduce a unique solution, but till then I’ll be very glad to hear your opinion on that.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=398462" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/Design/default.aspx">Design</category><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/Thoughts+and+Ideas/default.aspx">Thoughts and Ideas</category><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/DEV/default.aspx">DEV</category></item><item><title>10 Reasons to Love XAML</title><link>http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/12/22/10-reasons-to-love-xaml.aspx</link><pubDate>Sat, 22 Dec 2007 05:54:14 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:44489</guid><dc:creator>Tomer Shamam</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/tomershamam/rsscomments.aspx?PostID=44489</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.microsoft.co.il/blogs/tomershamam/commentapi.aspx?PostID=44489</wfw:comment><comments>http://blogs.microsoft.co.il/blogs/tomershamam/archive/2007/12/22/10-reasons-to-love-xaml.aspx#comments</comments><description>&lt;p&gt;&lt;/p&gt; &lt;p&gt;Many of my customers and students ask me:  &lt;p&gt;What is XAML good for? Why do I have to write XAML if I can write WPF with code?  &lt;p&gt;So I decided to write a post about it, sorted by the most important to the less essential.  &lt;p&gt;&amp;nbsp; &lt;h5&gt;1. It’s the Designer best friend&lt;/h5&gt; &lt;p&gt;WPF is not just about another UI platform, it’s also a methodology. It provides new tools and concepts for creating a modern presentation layer. Programmers write code, but when it comes to drawing…, OMG!  &lt;p&gt;To overcome this problem, a new member is introduced: a Designer. Designers usually are not developers, hence &lt;b&gt;&lt;i&gt;for&lt;/i&gt;&lt;/b&gt;, &lt;b&gt;&lt;i&gt;if&lt;/i&gt;&lt;/b&gt;, &lt;b&gt;&lt;i&gt;class&lt;/i&gt;&lt;/b&gt;, &lt;b&gt;&lt;i&gt;abstract&lt;/i&gt;&lt;/b&gt;, etc are all buzzwords for them. For a designer to feel at home, she has to work with familiar tools such as Adobe Illustrator, Expression Blend and Expression Design. Also she can read and write HTML and XML. Hence XAML is the ultimate markup for integrating the talents of both the Developer and Designer.  &lt;p&gt;&lt;em&gt;Express every visual aspect with XAML (or at least as much as you can) so the designer will be able to apply makeup on it.&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;2. It separates design from code&lt;/h5&gt; &lt;p&gt;You may agree that it is a good design principle to separate the UI design from the code behind. This way it will be easy to change, share and replace the UI. Separating them further with two different languages provides a higher level of decoupling.  &lt;p&gt;&lt;em&gt;Developer write code with C#/VB.NET where Designer design UI with XAML.&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;3. It is toolable&lt;/h5&gt; &lt;p&gt;Visual Studio is the best development environment ever. It provides so many tools for building projects, edit and compile files. But is it really necessary that Adobe Illustrator or Expression Design will do the same as it comes to WPF? Do they have to compile or generate C# or VB.NET code?  &lt;p&gt;XAML is the best option for an application such as described above for exporting 2D and 3D Vector Graphics and Animation. It is more reasonable to export graphics as XAML, without dealing with C#/VB.NET, assemblies, code generation and other coding stuff.  &lt;p&gt;&lt;em&gt;XAML is XML so you can also write export plug-ins for other applications running on Linux or other operating systems.&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;4. It’s more securable than IL&lt;/h5&gt; &lt;p&gt;XAML usually ends up with BAML, and code usually ends up with IL.  &lt;p&gt;&lt;em&gt;IL imposes a security risk where BAML is not!&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;5. It&amp;#39;s hierarchical&lt;/h5&gt; &lt;p&gt;Did you ever tried to initialize a hierarchical data such as Tree or data types based on the Composite Pattern within C#? I did that more than once, and each time I had a migraine.  &lt;p&gt;Neither C# nor VB.NET is hierarchical language. Usually a programming language is flat, hence it is hard to deal with hierarchical data within code.  &lt;p&gt;&lt;em&gt;Because the XML nature of XAML, it is the perfect tool for creating and manipulating hierarchical data. WPF is hierarchical!&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;6. It can be easily parsed, serialized and desirialized&lt;/h5&gt; &lt;p&gt;I love C#, but when it comes to parsing I better leave this painful job to the compiler team.  &lt;p&gt;&lt;em&gt;XAML is XML, it can be easily parsed serialized and desirialized. So in this case tools like XmlReader, XmlDocument, XamlReader and XamlWriter are my favorites.&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;7. It can be loose&lt;/h5&gt; &lt;p&gt;Many talents UI developers use XML to describe dynamic menus, toolbars, commands, etc. The absurd is that the code for reading this XML at runtime and turning it into objects is written again and again.  &lt;p&gt;&lt;em&gt;Use loose XAML so you will never have to write this code again. It is perfect for this situation.&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;8. It’s more readable than code&lt;/h5&gt; &lt;p&gt;When it comes to reading and understanding the structure of a UI, XAML is more readable than code.  &lt;p&gt;&lt;em&gt;Readable is a matter of taste, so I will leave it for Leo from The Matrix to decide.&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;9. It’s shorter than code&lt;/h5&gt; &lt;p&gt;Uri uri = new Uri(@“Images\Photo.png”, UriKind.Relative);  &lt;p&gt;BitmapSource bitmap = new BitmapSource(uri);  &lt;p&gt;Image image = new Image();  &lt;p&gt;Image.Source = bitmap;  &lt;p&gt;Button button = new Button();  &lt;p&gt;button.Content = image;  &lt;p&gt;&amp;nbsp; &lt;p&gt;&amp;lt;Button&amp;gt;  &lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Image Source=“Images\Photo.png” /&amp;gt;  &lt;p&gt;&amp;lt;/Button&amp;gt;  &lt;p&gt;&amp;nbsp; &lt;p&gt;&lt;em&gt;Who’s shorter?&lt;/em&gt;  &lt;h5&gt;&amp;nbsp;&lt;/h5&gt; &lt;h5&gt;10. It’s common&lt;/h5&gt; &lt;p&gt;Try to Google “WPF”…  &lt;p&gt;&lt;em&gt;Hello…, is there anybody out there? C#? VB.NET? Helloooooo!?&lt;/em&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=44489" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/Design/default.aspx">Design</category><category domain="http://blogs.microsoft.co.il/blogs/tomershamam/archive/tags/Thoughts+and+Ideas/default.aspx">Thoughts and Ideas</category></item></channel></rss>