Spatacoli

Category - Windows 8.1

  1. Windows 8.1 Update

    I’m a little late to the party of writing about Windows 8.1 Update, but I wanted to get a fair result. My initial thoughts on it were that I didn’t like any of the improvements they made for keyboard and mouse users. Until a couple days ago when I was forced to use Windows 8.1 long enough to install the Update. I have to concede that the keyboard and mouse improvements are wonderful. The added title bar for immersive apps is great and the addition of the power button on the start page is great. Also the addition of context menus to the start page is great. Overall I hope everyone out there in Windows 8 land updates to Windows 8.1 Update and does it soon. There are no more patches for Windows 8.1 without the Update. Also, if you are still using Windows 8 please find out how you can upgrade for free. It is very important that you are on the latest and greatest.

  2. EventToCommand is now built into Windows 8.1!

    In MVVM code is separated to make it easier to test. You write a View Model and bind it to the View. Sometimes the View has elements that trigger events that you want to listen for in the View Model. This is where EventToCommand comes in handy. However, up till now this has been a bit of a trick to do in Windows 8 because it isn't built in. You have to use a third party extension or write all the wiring up yourself.

    Until now. Windows 8.1 is coming to the rescue. Blend for Visual Studio 2013 includes behaviors such as EventTriggerBehavior to satisfy your InvokeCommandAction needs. I'm ashamed to say though that I'm not one to hit the old "Edit in Blend" link in Visual Studio. I prefer to do all the hard work by hand. Well here's how you can do it by hand.

    The first step is to add a reference to the Windows SDK item BehaviorsXamlSDKManaged in the project. I had to unload the project and edit the csproj file directly to get this in since it didn't show on the "Add Reference…" dialog.

     <ItemGroup>
    <!-- A reference to the entire .Net Framework and Windows SDK are automatically included --> 
    <SDKReference Include="BehaviorsXamlSDKManaged, Version=12.0" /> 
    </ItemGroup> 
    

    Next we need to add some new XML namespaces to our XAML page:

    xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:Core="using:Microsoft.Xaml.Interactions.Core"

    Here I'm using the same names that Blend gives them. I'm sure you can rename them to make them clearer. Particularly Core.

    Then you set the hooks in the XAML code. In this example I have a Button that I'm listening for the "PointerExited" event and sending in the item as a command parameter:

    <Interactivity:Interaction.Behaviors>
      <Core:EventTriggerBehavior EventName="PointerExited">
        <Core:InvokeCommandAction Command="{Binding OnPointerExited}" CommandParameter="{Binding}" />
      </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>

    Finally you hook this into your ViewModel using the same DelegateCommand infrastructure you would use for any other command.

    I know this is a brief overview, and if you'd like a full example please look me up on Twitter (@spatacoli) and ask for a full demo.

  3. Upgrading Apps to Windows 8.1 – Deprecated Methods

    In upgrading NOOK from Windows 8 to Windows 8.1 there are four methods/properties that we were using that have been deprecated since Windows 8. Here they are and the replacement:

    1) ScrollViewer.ScrollToVerticalOffset and ScrollViewer.ScrollToHorizontalOffset have been replaced with ScrollViewer.ChangeView(OffsetX, OffsetY, ZoomLevel)

    2) ApplicationView.View has been replaced with ApplicationView.GetForCurrentView().Orientation which is an ApplicationViewOrientation

    3) DisplayProperties.LogicalDpi has been replaced with DisplayInformation.GetForCurrentView().LogicalDpi

    The first one has a catch though. Previously if the horizontal scroll width was smaller than the requested position it would fail silently. Using ChangeView though it will throw an exception. What I’ve had to do in this case is wait until the GridView is loaded then I use an anonymous method to do the horizontal scroll.

    The second one also has some interesting properties to it. Previously we were interested in if we were in snap view, but snap view is no longer used in Windows 8.1 so you need to stop looking for it. We use the Orientation to detect portrait versus landscape only. Width of the screen is detected with a size changed event.

    Let me know if you have any more methods that are deprecated that are useful to know.