{"id":3728,"date":"2013-03-19T12:00:25","date_gmt":"2013-03-19T10:00:25","guid":{"rendered":"http:\/\/www.centigrade.de\/blog\/en\/?p=3728"},"modified":"2020-01-25T19:42:51","modified_gmt":"2020-01-25T18:42:51","slug":"from-windows-to-tiles-contrasting-winrts-ui-framework-with-wpf-another-case-study","status":"publish","type":"blog","link":"https:\/\/www.centigrade.de\/en\/blog\/from-windows-to-tiles-contrasting-winrts-ui-framework-with-wpf-another-case-study\/","title":{"rendered":"From windows to tiles: Contrasting WinRT\u00b4s UI framework with WPF \u2013 Another case study"},"content":{"rendered":"<p>A while back, we have published a <a href=\"http:\/\/www.centigrade.de\/en\/blog\/porting-a-windows-phone-7-app-to-windows-runtime-a-small-case-study\/\">small case study<\/a> illustrating our experiences gained in the course of porting an existing WP7-based application to WinRT. As we are continuously growing our competencies regarding WinRT development, we were able to identify a bunch of further differences between WinRT XAML and WPF XAML (as well as Silverlight or Windows Phone 7.X). In this blog post, we want to introduce you to some further prominent differences as well as important characteristics of the WinRT UI Framework that differentiate this API from WPF. Specifically, we will have a look at Bindings, Commands and DependencyProperties.<br \/>\n<!--more--><\/p>\n<h3>Bindings<\/h3>\n<p>As already suggested in our <a href=\"http:\/\/www.centigrade.de\/en\/blog\/porting-a-windows-phone-7-app-to-windows-runtime-a-small-case-study\/\">previous porting case study<\/a>, the WinRT API\u00b4s Binding class ships with rather reduced functionality compared to the implementation as supported by WPF. One characteristic of this limitation is the diminished <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/windows.ui.xaml.data.bindingmode\">binding mode enumeration: Windows Store apps<\/a> support neither OneWayToSource nor Default. Considering the following XAML snippet, the impact of the absence of the latter one becomes obvious:<\/p>\n<pre class=\"csharpcode\" style=\"font-size: small; color: black; font-family: Consolas, 'Courier New', Courier, Monospace; background-color: #ffffff;\"><span class=\"rem\" style=\"color: #008000;\">&lt;!-- WPF: implicitely binds TwoWay --&gt;<\/span> \r\n<span class=\"kwrd\" style=\"color: #0000ff;\">&lt;<\/span><span class=\"html\" style=\"color: #800000;\">TextBox<\/span> <span class=\"attr\" style=\"color: #ff0000;\">Text<\/span><span class=\"kwrd\" style=\"color: #0000ff;\">=\"{Binding Source={StaticResource ViewModel}, Path=Value}\"<\/span><span class=\"kwrd\" style=\"color: #0000ff;\">\/&gt;<\/span>\r\n \r\n<span class=\"rem\" style=\"color: #008000;\">&lt;!-- WinRT: implicitely binds OneWay --&gt;<\/span>\r\n<span class=\"kwrd\" style=\"color: #0000ff;\">&lt;<\/span><span class=\"html\" style=\"color: #800000;\">TextBox<\/span> <span class=\"attr\" style=\"color: #ff0000;\">Text<\/span><span class=\"kwrd\" style=\"color: #0000ff;\">=\"{Binding Source={StaticResource ViewModel}, Path=Value}\"<\/span><span class=\"kwrd\" style=\"color: #0000ff;\">\/&gt;<\/span>\r\n<\/pre>\n<p>As a TextBox generally represents an interface for user input, its Text property\u00b4s binding mode is set to TwoWay by default in WPF. As a consequence, a TextBox as defined above will update its underlying view model variable each time its Text property changes. In contrast, in a Windows Store app such a binding declaration on a TextBox\u00b4s Text property would be unidirectional (binding mode OneWay implicitely) thanks to the lacking \u201cDefault\u201d binding mode and thus does not trigger updates of the bound view model variable. Particularly when porting a WPF-based application to WinRT this characteristic is quite error-prone as we perceive a different behavior by writing the same code. Accordingly, we urge everybody planning to port a WPF app to WinRT to verify if explicit binding mode declarations are defined. Please note, that the binding mode enumeration in the Silverlight\/ Windows Phone 7.X API is similar to the WinRT version.<\/p>\n<h3>Commands<\/h3>\n<p>Our eventual findings concerning Commands in WinRT may be summed up as below:<\/p>\n<ol>\n<li>There are no built-in implementations of the <a href=\"http:\/\/msdn.microsoft.com\/de-de\/library\/system.windows.input.icommand.aspx\">ICommand <\/a>interface. Being an implementation of this very interface in WPF, the concept of routed commands has not been adopted in the WinRT XAML Framework. Moreover, the WPF counts 161 built-in static RoutedCommand properties (measured in version 4.0) which are not included either.<\/li>\n<li>The <a href=\"http:\/\/msdn.microsoft.com\/de-de\/library\/system.windows.input.icommandsource.aspx\">ICommandSource <\/a>interface does not exist anymore.<\/li>\n<li>The only class exposing an ICommand property is <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/apps\/windows.ui.xaml.controls.primitives.buttonbase\">ButtonBase<\/a>. Accordingly, the <a href=\"http:\/\/msdn.microsoft.com\/de-de\/library\/system.windows.input.inputbinding.aspx\">InputBindings<\/a> have neither been adopted in the WinRT Framework.<\/li>\n<\/ol>\n<p>As a consequence, Commands in Windows Store apps feel more similar to Silverlight\/ Windows Phone 7.X than they do to WPF. Please note that the statements made above are based on <a href=\"http:\/\/www.centigrade.de\/en\/blog\/from-windows-to-tiles-leveraging-reflection-to-inspect-and-contrast-wpf-with-winrt-xaml\/\">examinations leveraging the respective reflection APIs<\/a>.<\/p>\n<h3>Dependency Properties<\/h3>\n<p>Let\u00b4s briefly recap the way WPF <a href=\"http:\/\/en.csharp-online.net\/WPF_Concepts%E2%80%94Support_for_Multiple_Providers\">calculates a dependency property\u00b4s value<\/a> \u2013 to compute a dependency property\u00b4s actual value, the responsible engine successively runs through the following steps:<\/p>\n<ol>\n<li>Determination of a base value based on <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms743230.aspx\">precedence rules<\/a><\/li>\n<li>Evaluation (if expression)<\/li>\n<li>Appliance of animations<\/li>\n<li>Coercion<\/li>\n<li>Validation<\/li>\n<\/ol>\n<p>As opposed to this, the WinRT Framework lacks steps (4) and (5) and hence behaves more like Silverlight as well as Windows Phone 7.X in this regard.<\/p>\n<h3>Recap + Summary<\/h3>\n<p>At the bottom line, we already managed to identify a set of characteristics that distinguish the Windows Presentation Foundation (WPF) from the Windows RT Framework. Recapping and including our <a href=\"http:\/\/www.centigrade.de\/en\/blog\/porting-a-windows-phone-7-app-to-windows-runtime-a-small-case-study\/\">previous case study<\/a>\u00b4s outcomes as well, we may reveal the following provisional results:<\/p>\n<ol>\n<li>Different XML namespace declaration<\/li>\n<li>Missing Expression SDK<\/li>\n<li>Missing Property-\/Data Triggers<\/li>\n<li>Reduced BindingMode enum<\/li>\n<li>Missing MultiBindings<\/li>\n<li>Missing RoutedCommands<\/li>\n<li>Missing InputBindings<\/li>\n<li>DependencyProperty value calculation goes without coercion and validation<\/li>\n<\/ol>\n<p>In light of these findings, we may ascertain that the WinRT UI framework is rather guided by Silverlight than by WPF. Recalling the respective frameworks\u00b4 target platforms, this correlation appears to be pretty reasonable: both WinRT and Silverlight applications target sandboxed environments providing only a limited set of resources whereas the WPF goes without these boundaries and is consequently capable of implementing a surplus of functionalities.<\/p>\n<p><span style=\"font-size: xx-small;\">All trademarks or registered trademarks are properties of their respective owners.<\/span><\/p>\n","protected":false},"author":29,"featured_media":0,"template":"","tags":[191,189,208,210,212,214,44,192,40],"class_list":["post-3728","blog","type-blog","status-publish","hentry","tag-migration","tag-windows-8","tag-windows-rt","tag-winrt","tag-winrt-vs-silverlight","tag-winrt-vs-wpf","tag-wpf","tag-wpf-vs-rt","tag-xaml"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/blog\/3728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/users\/29"}],"version-history":[{"count":0,"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/blog\/3728\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/media?parent=3728"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.centigrade.de\/en\/wp-json\/wp\/v2\/tags?post=3728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}