The Dew Review – Windows Presentation Foundation 4.5 Cookbook

I recently gave away two copies of Packt’s new title, Windows Presentation Foundation 4.5 Cookbook. Packt also provided me with an eBook copy to review. I do quite a bit of WPF work at my day job these days, so I was very interested.

WPF 4.5 Cookbook is a great reference guide for mid-to-senior level WPF developers. It is not intended to teach beginners how to get started. It is for those times when experienced developers are facing a task that maybe they don’t do every day and need a quick refresher, or perhaps they’re using a particular technique for the first time. If you have a decent background in any kind of XAML development (Silverlight, WPF, Windows Phone, etc) and you will be working on WPF applications, this book will make a handy desktop companion.

The cookbook pattern is implemented well by the author. Each topic includes an introduction, a step-by-step guide on how to code the solution, an explanation of why to use the technique and how to take it further. Topics covered include layout, controls, styles, data binding, commands in MVVM, graphics/animation, and threading. While some new C# 5.0 and WPF 4.5 topics are covered, much of the book can be used as a guide for previous versions of WPF as well.

I think this book would be useful to almost any WPF developer with at least some experience and heartily recommend it.

 

del.icio.us Tags: ,,,

The Dew Review – Intel Next Generation Ultrabook™ with Windows 8: A Final Look

You can read my first two reviews of the Next Gen Ultrabook from Intel here:

  1. The Dew Review – Intel Next Generation Ultrabook™ with Windows 8: Initial Impressions
  2. The Dew Review – Intel Next Generation Ultrabook™ with Windows 8: Playing with Sensors

Intro

This is my third and final review of the Intel Ultrabook. I am happy to say it is not the end of my use of the machine. It has become my primary device for development and all other regular use outside of work. My wife and kids also love using it.

Family Time

I have three daughters. The six-year-old, Luci, likes to practice words and numbers on Mr. Anker Tests. It’s got a variety of Flash-based activities for pre-K and grade school kids. Luci really likes that she can use either the touchpad or the screen to interact with the site. Whenever she sees Windows apps on a non-touch-enabled device, she tends to reach for the screen first. This was not something that happened after using an iPod Touch, iPad or Kindle Fire. I think it’s seeing the same Windows UI that triggers it.

More Windows 8 Development

I have continued to look at the sensor APIs available in WinRT since my last review. I have created a couple other simple proof-of-concept type apps that just reference all the sensors and display and log the output. One of them is similar to my first C#/XAML SensorFun app, but I wrote it in HTML/JavaScript to see how things are different in that type of app. I found that outside of syntax, it’s pretty much the same. That app is called SensorFunJS, and here is a snippet of the JavaScript code.

(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;

    var orientationSensor;
    var app = WinJS.Application;

    function id(elementId) {
        return document.getElementById(elementId);
    }

    function onOrientationChanged(e) {
        switch (e.orientation) {
            case Windows.Devices.Sensors.SimpleOrientation.notRotated:
                id('orientationElement').innerHTML = "Not Rotated";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated90DegreesCounterclockwise:
                id('orientationElement').innerHTML = "Rotated 90 degrees";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated180DegreesCounterclockwise:
                id('orientationElement').innerHTML = "Rotated 180 degrees";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.rotated270DegreesCounterclockwise:
                id('orientationElement').innerHTML = "Rotated 270 degrees";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.faceup:
                id('orientationElement').innerHTML = "Face Up";
                break;
            case Windows.Devices.Sensors.SimpleOrientation.facedown:
                id('orientationElement').innerHTML = "Face Down";
                break;
            default:
                id('orientationElement').innerHTML = "Unknown orientation: " + e.orientation;
                break;
        }
    }

    app.onactivated = function (activationArgs) {
        if (activationArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
            
            orientationSensor = Windows.Devices.Sensors.SimpleOrientationSensor.getDefault();
            orientationSensor.addEventListener("orientationchanged", onOrientationChanged);
            
            WinJS.UI.processAll();
        }
    };
    
    app.start();
})();

Next, I found an article on Code Project with a Windows 8 WinForm app referencing the WinRT libraries and using the Sensor API. This same C# code could be used behind a WPF desktop application on WIndows 8. I plan on taking the ideas in this project to create my own library that can be shared across Windows 8 desktop applications. Here’s a sample of the code from Yvan’s article.

private void SensorListener()
{
    // Monitor accelerometer events.
    if (_accelerometer != null)
    {
        _accelerometer.ReportInterval = 0; // default
        _accelerometer.ReadingChanged += AccelerometerOnReadingChanged;
        _accelerometer.Shaken += (s, a) => _shaken++;
        Log("Shake activity will be monitored.");
    }

    // Monitor compass events.
     if(_compass != null)
    {
        _compass.ReportInterval = 0; // default
        _compass.ReadingChanged += CompassOnReadingChanged;
    }

    // Monitor gyro events.
    if(_gyrometer != null)
    {
        _gyrometer.ReportInterval = 0; // default
        _gyrometer.ReadingChanged += GyrometerOnReadingChanged;
    }

    // Monitor light sensor events.
    if (_light != null)
    {
        _light.ReportInterval = 0; // default
        _light.ReadingChanged += LightOnReadingChanged;
    }

    // Monitor position sensor events.
    if (_geolocator != null)
    {
        _geolocator.ReportInterval = 1000;
        _geolocator.MovementThreshold = 1;
        _geolocator.DesiredAccuracy = PositionAccuracy.High;
        _geolocator.StatusChanged += GeolocatorOnStatusChanged;
        _geolocator.PositionChanged += GeolocatorOnPositionChanged;
    }

     // Monitor NFC proximity events.
     if (_proximity != null)
    {
        _proximity.DeviceArrived += ProximityDeviceArrived;
        _proximity.DeviceDeparted += ProximityDeviceDeparted;
    }
            
    // The sensor loop.
    while (true)
    {
        if (_stopping)
            return;
        Thread.Sleep(0); // Defer to other threads that need cycles.
    }
}

As you can see, the code is no different than that of a WinRT app.

Intel has a really good article titled “Using Windows 8 WinRT API from desktop applications.” I highly recommend checking that out if you are developing desktop applications for Windows 8. There are a lot of great (and simple to use) APIs in WinRT. Having the ability to leverage them in our desktop apps is really exciting.

Sensors in the Real World

As far as the usefulness of sensors in real world applications, I think the biggest opportunity lies in game development. There could also be some simulator and health care related applications for some of these apps as well.

I am in the early stages of creating an app called Steady Hands Challenge. You can read my overview of the app on Code Project. Basically, you hold the Ultrabook on the palms of your hands, and the app will use charts on the screen to instruct the user which way to tilt the Ultrabook. The closer you keep the actual X/Y/Z lines to the target lines, the higher your score. Any shaking detected by the accelerometer will result in a penalty. Although I originally envisioned this WPF app as a sort of game, I could see how something similar could be used to gamify physical therapy. As long as your not worried about patients dropping your Ultrabook.  Smile

A Final Wrap Up

As I have repeatedly stated, I really have enjoyed developing on this machine. I truly believe that Ultrabooks with Windows 8 are the perfect developer machine today. They provide the power and speed needed to run multiple instances of Visual Studio or any other IDE. The touch screen and sensors also eliminate the need to have a separate tablet for testing your apps. I can write apps that use complex gestures and test with a simple F5. This saves time, money and headaches.

My name is Alvin Ashcraft, and I approve this Ultrabook.

 

Disclosure of Material Connection: I received one or more of the products or services mentioned above for free in the hope that I would mention it on my blog. Regardless, I only recommend products or services I use personally and believe my readers will enjoy. I am disclosing this in accordance with the Federal Trade Commission’s 16 CFR, Part 255: “Guides Concerning the Use of Endorsements and Testimonials in Advertising.”

 

The Dew Review – DXTREME: Cross-Platform Application Dev Tools by DevExpress

DevExpress has released a new set of cross-platform tools that enable developers to create rich web applications targeting mobile and desktop browsers. DXTREME is the name of the new package that aims to make developers more productive in these scenarios.

Just how easy is it to jump in and build a simple application? I have had little experience developing for platforms other than Windows and Windows Phone, and I have been wanting to find a way to target iOS and Android. So, when I was asked to take a look at DXTREME, I jumped at the opportunity.

Installation and Getting Started

Installation was quick and painless, as is the case with all DevExpress tools (see my review of their WPF suite). After installing, a new DevExpress template category is added in Visual Studio 2012’s New Project dialog. In there, select the  DXTREME 12.2 Application Project template to get started.

NewProject

The default project contains quite a few files. App.html is the default page and acts as the container for all of your views. Index.html is the default view loaded by App.html. Each of these html files has a corresponding .js and .css file. The navigation bar for DXTREME apps has its files located under layoutsNavbar. The default navigation buttons are Home and About (which loads the included About.html file). The datadb.js file performs data retrieval for the app.

SolutionExplorer

Data Retrieval

I am a big fan of the ASP.NET Web API, and I wanted to see how easily I could get a DXTREME application to work with a Web API data source. I downloaded the Contact Manager Web API sample and running in IIS Express on port 8081. Getting the data in my app was as simple as adding this code to db.js.

 1: $(function() {
 2:     ContactSample.db = new DevExpress.data.RestService({
 3:         url: "http://localhost:8081/api/",
 4:         sources: {
 5:             contacts: {
 6:                 read: "Contacts.json"
 7:             }
 8:         }
 9:     });
 10: });

The included DevExpress JavaScript libraries have functions to retrieve data from different types of data sources. The next step is to make the contact data available by calling the data function from the ViewModel (index.js).

 1: ContactSample.index = function(params) {
 2: 
 3:     var viewModel = {
 4:         contacts: {
 5:             store: ContactSample.db.contacts
 6:         }
 7:     };
 8: 
 9:     return viewModel;
 10: };

The View

DXTREME uses knockout.js for binding data in views to the ViewModels. So, the last thing to do to get the main page up and running is adding a few lines of code to index.html.

 1: <div data-role="view" data-name="index" data-title="Home">
 2:     <div data-target-placeholder="content" >
 3:         <h2 style="padding: 4px">My Contacts</h2>
 4:         <p style="padding: 2px">Contact name, email and twitter handle.</p>
 5:         <div data-bind="dxList: { dataSource: contacts }">
 6:             <div data-dx-role="template" data-dx-name="item">
 7:                 <div data-bind="uri: 'ContactDetail/{ContactId}'">
 8:                     <div data-bind="text: Name"></div>
 9:                 </div>
 10:             </div>
 11:         </div>
 12:     </div>
 13: </div>

Now when we run the app, we get a list of contacts from the Web API service in our app. The page can be viewed in simulators for iPad, iPhone, Android or Android tablets. There are also options to view the simulators in portrait or landscape mode. This is what our page looks like in the iPhone simulator.

Sim

Navigation is also very easy to accomplish in DXTREME. I added a second page to display contact details for a selected contact name with very little effort.

Page2

You can download the entire project here.

The Path Forward

As a next step in your DXTREME learning experience, I recommend downloading a trial version here, and then head over to the DXTREME Learning Center. There is a simple app walkthrough with code and a simulator as well as detailed documentation around more advanced controls, data access, routing and navigation.

I enjoyed building with DXTREME and plan to use it on a couple of personal projects in the near future. I recommend giving the tools a try for yourself.

 

Disclosure of Material Connection: I received one or more of the products or services mentioned above for free in the hope that I would mention it on my blog. Regardless, I only recommend products or services I use personally and believe my readers will enjoy. I am disclosing this in accordance with the Federal Trade Commission’s 16 CFR, Part 255: “Guides Concerning the Use of Endorsements and Testimonials in Advertising.

 

Mastodon
github.com/alvinashcraft