Compiled Experience Windows Platform Development en Fri, 17 Feb 2017 09:16:23 +0000 Fri, 17 Feb 2017 09:16:23 +0000 Caliburn.Micro roadmap <p>In the last couple of days I’ve put together and published a <a href="">roadmap</a> for Caliburn.Micro, there’s a couple of reasons for this. The first is help me plan what I want to do and what will be needed, the second to let people know what to expect in the future (although I deliberately didn’t attach dates to anything).</p> <p>It’s been a rough six months for me personally in terms of getting time to do open source development, but my life has settled down a lot now and I’m hoping to get back into it. This roadmap is the first step in that path.</p> <p>Part of this is also working out how I want to do development on these disparate areas and hopefully encourage other people to help out. I’m considering using GitHub projects to sketch things out in terms of adding notes and potentially pointing the way for others.</p> <p>Would love to know your thoughts on any of this and the <a href="">roadmap</a> itself.</p> Fri, 17 Feb 2017 00:00:00 +0000 (Nigel Sampson) Supporting Xamarin.Forms Tabbed Page in Caliburn.Micro <p>One of the best features of Caliburn.Micro in my opinion is get away from “one view model per screen” and starting to compose view models together to form the screen.</p> <p>The framework itself supplies conductors to help facilitate this, as well as the behaviour of <code class="highlighter-rouge">View.Model</code> as as “Template Selector” on steroids.</p> <p>As a quick refresher what <code class="highlighter-rouge">View.Model</code> does when applied to <code class="highlighter-rouge">ContentControl</code> (or <code class="highlighter-rouge">ContentView</code> in Xamarin.Forms) is locate the view appropriate to the bound view model and inject it into the control (while binding the view and view model together).</p> <p>For instance given the following xaml:</p> <div class="language-xml highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;Grid&gt;</span> <span class="nt">&lt;ContentControl</span> <span class="na">cm:View.Model=</span><span class="s">"{Binding ActiveItem}"</span> <span class="nt">/&gt;</span> <span class="nt">&lt;/Grid&gt;</span> </code></pre> </div> <p>The contents of the <code class="highlighter-rouge">ContentControl</code> will be the view appropriate for the type of <code class="highlighter-rouge">ActiveItem</code>. If for instance it was <code class="highlighter-rouge">ProductsListViewModel</code> then the contents would be <code class="highlighter-rouge">ProductsListView</code>. What’s really great is that as <code class="highlighter-rouge">ActiveItem</code> changes to am instance of another type then the contents wil update with the new view as well.</p> <p>So how does this fit with <code class="highlighter-rouge">TabbedPage</code> in Xamarin.Forms?</p> <p>Well it works pretty seamlessly with a few tricks.</p> <p>First we’ll start with the view model that represents the tabbed page itself, I typically call this the shell. It inherits from <code class="highlighter-rouge">Conductor&lt;PageViewModel&gt;.Collection.OneActive</code> which essentially means that this view model conducts a collection of page view models where one is active at a time. This maps nicely to how a tab UI works.</p> <div class="language-csharp highlighter-rouge"><pre class="highlight"><code><span class="k">public</span> <span class="k">class</span> <span class="nc">ShellViewModel</span> <span class="p">:</span> <span class="n">Conductor</span><span class="p">&lt;</span><span class="n">PageViewModel</span><span class="p">&gt;.</span><span class="n">Collection</span><span class="p">.</span><span class="n">OneActive</span> <span class="p">{</span> <span class="p">...</span> <span class="p">}</span> </code></pre> </div> <p>In our shell view we have the <code class="highlighter-rouge">TabbedPage</code> itself, bound to the <code class="highlighter-rouge">Items</code> and <code class="highlighter-rouge">ActiveItem</code> of the shell view model. For the item template we have one gotcha. <code class="highlighter-rouge">TabbedPage</code> expects it’s contents to inherit from <code class="highlighter-rouge">Page</code>, so the root element of our data template but be <code class="highlighter-rouge">ContentPage</code>. Fortunately <code class="highlighter-rouge">View.Model</code> can handle this with no problem. We also make use of the display name property on <code class="highlighter-rouge">Screen</code> to supply the title for each tab.</p> <div class="language-xml highlighter-rouge"><pre class="highlight"><code><span class="nt">&lt;TabbedPage</span> <span class="na">ItemsSource=</span><span class="s">"{Binding Items}"</span> <span class="na">SelectedItem=</span><span class="s">"{Binding ActiveItem, Mode=TwoWay}"</span><span class="nt">&gt;</span> <span class="nt">&lt;TabbedPage.ItemTemplate&gt;</span> <span class="nt">&lt;DataTemplate&gt;</span> <span class="nt">&lt;ContentPage</span> <span class="na">Title=</span><span class="s">"{Binding DisplayName}"</span> <span class="na">cm:View.Model=</span><span class="s">"{Binding}"</span> <span class="nt">/&gt;</span> <span class="nt">&lt;/DataTemplate&gt;</span> <span class="nt">&lt;/TabbedPage.ItemTemplate&gt;</span> <span class="err">&lt;</span>/TabbedPage </code></pre> </div> <p>In our shell we can now add some pages:</p> <div class="language-csharp highlighter-rouge"><pre class="highlight"><code><span class="k">protected</span> <span class="k">override</span> <span class="k">void</span> <span class="nf">OnInitialize</span><span class="p">()</span> <span class="p">{</span> <span class="n">Items</span><span class="p">.</span><span class="nf">Add</span><span class="p">(</span><span class="k">new</span> <span class="nf">ProductsListViewModel</span><span class="p">());</span> <span class="n">Items</span><span class="p">.</span><span class="nf">Add</span><span class="p">(</span><span class="k">new</span> <span class="nf">LocationsViewModel</span><span class="p">());</span> <span class="n">Items</span><span class="p">.</span><span class="nf">Add</span><span class="p">(</span><span class="k">new</span> <span class="nf">ContactViewModel</span><span class="p">());</span> <span class="nf">ActivateItem</span><span class="p">(</span><span class="n">Items</span><span class="p">[</span><span class="m">0</span><span class="p">]);</span> <span class="p">}</span> </code></pre> </div> <p>As the tabs are selected our item template will locate the correct view for the above view models.</p> <p>What’s really interesting about this is that our shell doesn’t have to care about how the pages below it look or work. It can focus on it’s single reponsiblity which is the tabs themselves and any behaviour conducting their flow.</p> Thu, 02 Feb 2017 00:00:00 +0000 (Nigel Sampson) Customising Pluralisation in Caliburn.Micro <p>Caliburn.Micro uses pluralisation in it’s conventions. It’s what turns an <code class="highlighter-rouge">x:Name</code> of <code class="highlighter-rouge">Products</code> into bindings of the <code class="highlighter-rouge">Products</code> and <code class="highlighter-rouge">SelectedProduct</code> properties.</p> <p>To be more accurate Caliburn.Micro uses Singularisation, and it’s implementation is rather naive that certainly don’t cope with the variety the english language provides, let alone other languages.</p> <p>It’s current implementation is:</p> <div class="language-csharp highlighter-rouge"><pre class="highlight"><code><span class="k">public</span> <span class="k">static</span> <span class="n">Func</span><span class="p">&lt;</span><span class="kt">string</span><span class="p">,</span> <span class="kt">string</span><span class="p">&gt;</span> <span class="n">Singularize</span> <span class="p">=</span> <span class="n">original</span> <span class="p">=&gt;</span> <span class="p">{</span> <span class="k">return</span> <span class="n">original</span><span class="p">.</span><span class="nf">EndsWith</span><span class="p">(</span><span class="s">"ies"</span><span class="p">)</span> <span class="p">?</span> <span class="n">original</span><span class="p">.</span><span class="nf">TrimEnd</span><span class="p">(</span><span class="sc">'s'</span><span class="p">).</span><span class="nf">TrimEnd</span><span class="p">(</span><span class="sc">'e'</span><span class="p">).</span><span class="nf">TrimEnd</span><span class="p">(</span><span class="sc">'i'</span><span class="p">)</span> <span class="p">+</span> <span class="s">"y"</span> <span class="p">:</span> <span class="n">original</span><span class="p">.</span><span class="nf">TrimEnd</span><span class="p">(</span><span class="sc">'s'</span><span class="p">);</span> <span class="p">};</span> </code></pre> </div> <p>There are however some fanstasic libraries out there to deal with manipulating language in this way, and Caliburn.Micro can be updated to use them. I’m talking in particular about the library <a href="">Humanizer</a>.</p> <p>Having the following in our application configure code switches the framework to use Humanizer for it’s conventions and be able to deal with all the property names it couldn’t deal with before.</p> <div class="language-csharp highlighter-rouge"><pre class="highlight"><code><span class="n">ConventionManager</span><span class="p">.</span><span class="n">Singularize</span> <span class="p">=</span> <span class="n">original</span> <span class="p">=&gt;</span> <span class="n">original</span><span class="p">.</span><span class="nf">Singularize</span><span class="p">(</span><span class="n">inputIsKnownToBePlural</span><span class="p">:</span> <span class="k">false</span><span class="p">);</span> </code></pre> </div> Fri, 20 Jan 2017 00:00:00 +0000 (Nigel Sampson) NDC Sydney Video <p>Forgot to post about it at the time, but the video for talk <a href="">Cross Platform Mobile with XAML and MVVM</a> from NDC Sydney is available online..</p> <p>All the demos for this talk can be found on <a href="">GitHub</a>.</p> Tue, 10 Jan 2017 00:00:00 +0000 (Nigel Sampson) MVP renewed for 2017 <p>Pleased to say that I’ve had my Microsoft MVP renewed for the fourth year.</p> <p>Last year was a reasonably quiet year in terms of activity and I’m certainly looking to step it up this year.</p> <p>Although according to some TED talks announcing goals increase the likelihood of failure, so you’ll just have to wait and see.</p> Mon, 09 Jan 2017 00:00:00 +0000 (Nigel Sampson) My new cross platform setup <p>These days I’m doing more cross platform mobile work at home and decided to try a new approach.</p> <p>I’m using a Mac Mini for iOS / Xamarin work but having a dedicated monitor for it felt wasteful since it wasn’t used that often (it mostly functioned as a built server).</p> <p>I’ve been hearing people lately raving about ultra wide screen monitors and thought I’d give it a go.</p> <p>I picked up a <a href=";l=en&amp;s=bsd&amp;cs=hkbsd1&amp;sku=210-AEBV">Dell U3415W</a> and so far am in love with it. While doing Windows &amp; Android development I can give the full screen real estate to Windows, the Dell Display Manager that comes with the monitor lets me set up custom snap points for my windows. So far the one I like the best is two thirds for Visual Studio, then divide the rest of the horizontal space in two vertically for things like Powershell, emulators and the like. The total available resolution is 3440 x 1440.</p> <p>Where it really steps up is doing iOS / Xamarin development, I can switch on Picture by Picture mode giving half the screen to the Windows machine and half to the Mac. The Windows machine is using HDMI and the Mac Display Port. This gives each device 1720 x 1440 to play with which is plenty.</p> <p><a href="/content/images/posts/cross-platform-setup.jpg"><img width="600" src="/content/images/posts/cross-platform-setup.jpg" /></a></p> <p>Installing <a href="">Synergy</a> on both machines means I can use the same mouse and keyboard for both including copy &amp; pasting. The whole thing is so seamless I occasionally find myself trying to drag windows from one side to the other.</p> <p>It’s only been a few weeks so far but at the moment I can highly recommend it.</p> Sat, 28 May 2016 00:00:00 +0000 (Nigel Sampson) Speaking at NDC Sydney <p>Blown away to say that I’ll be speaking this upcoming August at <a href="">NDC Sydney</a> on <a href="">Cross Platform Mobile with XAML and MVVM</a>. There’s an awesome <a href="">speakers list</a> so I’m very excited to attend and see a lot of them speak for the first time. Getting this many great speakers in the same event in this part of the world is a rare feat so I’d recommend taking advantage of it and getting <a href="">your ticket</a> soon!</p> Tue, 17 May 2016 00:00:00 +0000 (Nigel Sampson) Auckland Azure Meetup Slides <p>Last month I did a talk at the <a href="">Auckland Azure Lunchtime meetup</a>, it covered using Azure Mobile Apps (formerly Mobile Services) to build a cross platform application using Xamarin.</p> <p>You can view the <a href="!275407&amp;authkey=!ANlM8bnryckcXig&amp;ithint=file%2cpptx">slides</a> and the <a href="">demos</a> respectively. Building the demos I was pleasantly surprised how easy it was to fit the SDK into my normal MVVM patterns. Often these “backend as a service” SDK’s can be very invasive, but with some well defined interfaces all was well.</p> Fri, 06 May 2016 00:00:00 +0000 (Nigel Sampson) Xamarin acquisition thoughts <p>Last week it was <a href="">announced</a> that Microsoft would be acquiring <a href="">Xamarin</a>, the popular toolset for building cross platform mobile apps with C#.</p> <p>I presented a number of talks last year on <a href="">building cross platforms mobile apps with Xamarin</a> that you can view online.</p> <p>It’s certainly an interesting piece of news, most people expected this to be announced at last year’s Build (or even the year before). Back then there was a school of though that it was better to keep Xamarin as a close partner rather than acquiring them. The belief was that this would better enable Xamarin to work with other <em>“competitors</em>” such as Apple, Google and IBM.</p> <p>I think now in 2016 it makes a lot of sense, the developer pick up of UWP is slow (IMO because there’s currently on one platform with the desktop) and Microsoft need ways to drive more apps to the UWP platform.</p> <p>Last year most of the announcements were around the application bridges, Astora, Centennial, Islandwood and Windsor (Android, Classic Windows, iOS and Web) as a way to bring more apps into the store (and hopefully the platform as well). Since the Astoria has been cancelled, we haven’t see much of Centennial but Islandwood is looking really good.</p> <p>This strategy didn’t make themselves popular with a lot of Windows developers who thought these technologies would render them obsolete (a line of thought I didn’t wholly agree with).</p> <p>Microsoft appears to be positioning themselves quite nicely in the cross platform cloud and developer tools space (I think it’s telling that announcement was on Scott Guthrie’s blog). By having a tool-set where it isn’t about migrating old apps but creating new cross platform apps I think they can better push Windows as a third platform as well as Android and iOS.</p> <p>My thoughts on what may change over the next year or so.</p> <ul> <li>Xamarin subscription to be rolled into MSDN.</li> <li>Test Cloud to be part of Azure.</li> <li>Some people think Xamarin Studio may merge with Visual Studio Code, I doubt that. We may see the end of Xamarin Studio with efforts focussed on Visual Studio.</li> <li>Android Player to be deprecated in favour of Visual Studio Android Emulator.</li> <li>Hopefully better support for the Windows platforms in Xamarin.Forms, the default renderers are terrible.</li> <li>Xamarin Insights to be merged with Application Insights / HockeyApp.</li> </ul> <p>Looking forward to what will be announced at Build, sadly will be missing this year though.</p> Tue, 01 Mar 2016 00:00:00 +0000 (Nigel Sampson) Caliburn.Micro 3.0.0 <p>After a <strong>prolonged</strong> period in beta <a href="">Caliburn.Micro 3.0.0</a> has just been pushed to nuget.</p> <p>This release stuck around in beta a lot longer than I wanted, mostly due to a series of overlapping circumstances. Some issue comes up where it wouldn’t make sense to release till it has been resolved, by that time another has cropped up. This is pretty normal for most projects but when only some of the issues are under your control it becomes very frustrating.</p> <p>I’m really glad <a href="">Xamarin.Forms</a> made it into this release, it’s not fully featured without programmatic access to <code class="highlighter-rouge">x:Name</code> but it’s still a great story. The idea we can have a view model that is able to be used across all mobile platforms and even older desktop platforms such as WPF at the same time is really compelling.</p> <p>Check out the full <a href="">announcement</a> for the full details for the release.</p> Tue, 01 Mar 2016 00:00:00 +0000 (Nigel Sampson)