Wintellect Blogs

From Zero to Hero in Xamarin Forms in 53 Minutes

Jeff Prosise

3 Jul , 2015  

image.png

Looking for a fast way to get up to speed on Xamarin Forms? There are tons of learning resources out there, including a series of articles I published this spring, the first of which can be found here. But while some developers prefer learning by reading, others find video training the best learning medium. Which is why I recorded a 53-minute video entitled Introduction to Xamarin Forms and conspired with the folks at WintellectNOW to make it available for free. It covers the basics of using Visual Studio 2015 and Xamarin Forms to build apps for iOS, Android, and Windows Phone, and it comes with 30 MB of downloadable sample code. In future videos, I’ll cover topics such as custom renderers and process lifetime management. For now, enjoy the inaugural video, and have fun learning Xamarin Forms!

 

imageRead more

, ,

Wintellect Blogs

Handling the Back Button in Windows 10 UWP Apps

Jeff Prosise

30 Jun , 2015  

Wrong-Way-Go-Back

The cool thing about Universal Windows Platform (UWP) apps is that they run on an assortment of devices, from PCs, tablets, and phones to (soon) Xboxes and HoloLens, among others. Personally, I can’t wait to see some of the apps I’ve written light up on my kids’ Xbox. They’ll think I’m a hero (“my dad writes Xbox apps!”) even though I’m not.

But as every hero knows, with great power comes great responsibility. One of the issues you’ll run into when writing a UWP app is how to handle the Back button. Windows phones have Back buttons, but other devices don’t. One way to handle the Back button on phones is to add a reference to Microsoft’s Mobile Extension SDK and write adaptive code that responds to HardwareButtons.BackPressed events, as I wrote about in a previous post. Of course, that doesn’t solve the problem of allowing users to navigate backward on devices that lack Back buttons. Which is why Microsoft introduced the Windows.UI.Core.SystemNavigationManager class. SystemNavigationManager does two important things for you:

  • Upon request, it displays a software Back button when your app is running on a device without a Back button
  • It allows you to handle clicks of the Back button (software or hardware) without adding extension SDKs and without writing adaptive code

Here’s what Contoso Cookbook looks like on a PC with a SystemNavigationManager-provided Back button:

Cookbook

Making the Back button appear requires just one line of code:

SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;

Responding to clicks of the Back button is a simple matter of wiring up a handler for SystemNavigationManager.BackRequested events:

SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) =>
{
    // TODO: Go back to the previous page
};

The beauty of it is that this code works without change on phones and other devices.… Read more

,

Wintellect Blogs

Angular2 Databinding is Fast!

Josh Carroll

25 Jun , 2015  

fast

I’ve been working with the Angular2 alpha ever since ng-conf 2015, and it has been pretty awesome to see how the framework is shaping up. I’ll be the first to admit that the bleeding edge tax is high, but it has been worth it to see just how powerful the next version of Angular is going to be.

The databinding system in Angular2 is so much better than the previous version that it is hard to talk about it in the abstract. I could go into a bunch of boring technical details, but I think seeing is believing.

The Setup

I wanted to see just how fast the new data binding system was, so I thought… why not animate a bunch of elements using nothing but databinding.

<table class="table table-striped table-condensed table-floating">
    <tbody>
        <tr *ng-for="#row of statusBoard">
            <td *ng-for="#col of row" [style.top]="col.top" [style.left]="col.left">&nbsp;</td>
        </tr>
    </tbody>
</table>

If you aren’t familiar with the syntax, don’t worry, basically I am using a nested repeater to create a bunch of rows and columns, and then data binding their position on the page.… Read more

, ,

Wintellect Blogs

Azure Bits #3– Adding a Message to an Azure Queue

Rik Robinson

16 Jun , 2015  

MicrosoftAzureBanner

In Azure Bits #2 – Saving the Image to Azure Blob Storage, we were able to save our image to Azure Blob Storage and verify that this all went according to plan after re-publishing our site to Azure.

In this Azure Bit, we will take a look at the Azure Queue service and we will place a message in the queue to signal that our newly-uploaded image is ready to be processed.

The first thing we will need to do is to create our IQueueService/QueueService to abstract the interaction with the Azure Queue service.  We’ll just need one method for now.

 

IQueueService.cs
  1. public interface IQueueService<T> where T: new()
  2. {
  3.     Task AddMessageToQueueAsync(string messageId, T messageObject);
  4. }

We’ll need to know the queue name for our Azure Queue and we’ll need the Blob Storage Connection string, so I’ll go ahead and add the ImagesQueue name to our appSettings in web.config.

web.config – appSettings
  1. <appSettings>
  2.   <add key=ImageRootPath value=https://imagemanipulator3.blob.core.windows.net/images />
  3.   <add key=ImagesContainer value=images />
  4.   <add key=ImagesQueue value=images />
  5. </appSettings>

 

Finally, here’s the initial skeleton of QueueService. … Read more

, , ,

Wintellect Blogs

Pooling Buffers for Better Memory Management

Sergio Loscialo

9 Jun , 2015  

shutterstock_210317662

Occasionally, you need a more robust solution to solve a problem.

In my last post, I wrote about the horrors of this small code snippet:

public byte[] Serialize(object o)
{
    using (var stream = new MemoryStream())
    {
        MySerializer.Serialize(stream, o);
        return stream.ToArray();
    }
}

One way to alleviate the memory pressure that can be caused by frequent creation and destruction of large objects is to tell the .Net garbage collector to compact the Large Object Heap (LOH) using:

GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;

However, this solution, while it may reduce the memory footprint of your application, does nothing to really solve the initial problem of allocating all that memory in the first place. As I mentioned in my last post, one way to accomplish that goal is to use a buffer pool.

The Buffer Manager

Instead of writing my own buffer manager, I am going to use the implementation Microsoft provides in the Windows Communication Framework (WCF) called the BufferManager. Now that WCF is open source you can go look at the implementation of BufferManager here.

The BufferManager essentially allocates a large chunk of contiguous memory and sets it aside for later use. You can create an instance of a BufferManager by calling the CreateBufferManager() static method as follows:

BufferManager.CreateBufferManager(maxPoolSize, maxBufferSize);

The first parameter, maxPoolSize represents how much memory you want the BufferManager to allocate in total.… Read more

, ,

Wintellect Blogs

Deploying an ES6, JSPM, NodeJS Application to Azure

Dave Baskin

3 Jun , 2015  

azure-logo

I have a simple NodeJS application that I want to deploy to Microsoft Azure. Fortunately, there already exists detailed instructions, on how to accomplish this. But I want to add a couple of extra things. The Node application will be written using ES6, the latest version of Javascript, and also use JSPM, a newer generation package manager for Javascript components.

Why do we need a new package manager? Doesn’t Bower and Browserify already serve this purpose well? Yes, but JSPM brings a few more useful ideas to the table:

  • JSPM pulls components directly from their source, either GitHub or NPM, rather than having to package components with a separate registration file.
  • JSPM integrates with Babel to automatically compile ES6 source. The compilation of the source can happen in the browser (so that a build step is not required) or as part of generating a web application to be deployed in a production environment.
  • JSPM (through the SystemJS universal module loader) supports different module formats, such as ES6, AMD, or CommonJS, so your code works well with existing code. SystemJS also supports a plugin system that can do things like loading CSS style sheets dynamically.

The AngularJS Application

The application to be deployed is here.… Read more

, ,

Wintellect Blogs

Azure Bits #2 – Saving the Image to Azure Blob Storage

Rik Robinson

22 May , 2015  

MicrosoftAzureBanner

Creating the Azure Storage Account

In Azure Bits #1 – Up and Running, we got a skeleton in place for our web application that will allow the user to upload an image and we published our Azure Image Manipulator Web App to Azure.  Our next task is taking this uploaded image and saving it into Azure Blob Storage.

The first thing we need to do is to create an Azure Storage account in the Azure Portal.  Once logged into the Portal, you’ll want to click on the big green plus sign for New in the top left.

image

Next, you’ll want to select Data + Storage and then Storage to get to the configuration blade for your new storage account.

image

Here, you’ll want to enter a unique name for your Azure Storage account. Note that this name must be globally unique and must be a valid URL. You’ll also want to make sure that the physical location you select is closest to the consumers of your data as costs can increase based on the proximity of the consumer to the storage region. You can leave the rest of the information with the defaults and then click the Create button.  Azure will grind away for a bit to create your storage account as you watch an animation on your home screen.… Read more

, , , , ,

Wintellect Blogs

Lighting up Native Platform Features in Xamarin Forms – Part 2

Keith Rome

20 May , 2015  

lighting-up-xf-feat

In the previous post I implemented a custom attached property to be used in Xamarin Forms XAML when a built-in accessory view is desired on a table cell. In this follow-up we will continue and build out the iOS renderer that is responsible for actually enabling the feature in our running application.

What about Android and Windows Phone – won’t they be affected too? That’s the beauty of the Xamarin Forms rendering model – it is up to each platform to decide how to natively implement the controls described in XAML markup. In this case, we have extended the existing XAML (not replaced it), and so the Android and Windows Phone renderers will simply just ignore the extensions unless we customize the renderers for those platforms as well.

Badge-Xamarin

TableView Rendering

Note: The following information comes through decompilation and inspection of the iOS renderers found in Xamarin.Forms.Platform.iOS (this assembly can be found in your Xamarin.iOS installation, or in your debug/bin output folder after compiling a Xamarin Forms project for iOS). I used JetBrains dotPeek to decompile the source from that assembly file.

The process of mapping a XAML TableView or ListView to a native UITableView/UITableViewSource and the various Xamarin Forms cell types to UITableViewCell objects is performed by a fairly complex orchestra of intertwined classes in the default iOS rendering system.… Read more

,

Wintellect Blogs

Lighting up Native Platform Features in Xamarin Forms – Part 1

Keith Rome

19 May , 2015  

lighting-up-xf-feat

In my last few posts I introduced a simple app that lets you browse the various built-in font variations supported by Xamarin Forms. If you recall, the application adopted a “stack navigation” design, which is quite common in mobile applications. However, there is one small flaw with our implementation so far – on the iOS platform it is customary to indicate that a ListView/TableView cell can be used to “drill down” into the navigation stack by including a “disclosure accessory” on the far right end of each cell. This accessory can be seen in the iOS Settings app below (the small chevron icons in the right margin of each cell):

image

Disclosure Indicators in the iOS System Settings App

Now, we could simply change our cell templates to add a custom image aligned to the right edge – but that wouldn’t be 100% correct. A Xamarin Forms TableView or ListView maps to the native UITableView, and if you review the iOS programming guide for Table Views you can see that there is built-in support for these that is provided by the operating system. These built-in icons can vary from one version of iOS to the next, and by using them (instead of custom icons) we can be assured that our application will continue to look correct as the platform evolves.… Read more

, ,

Wintellect Blogs

Hey, Who Stole All My Memory?

Sergio Loscialo

16 May , 2015  

shutterstock_241808626

Sometimes a little piece of seemingly innocuous code can cause a significant amount of trouble:

public byte[] Serialize(object o)
{
    using (var stream = new MemoryStream())
    {
        MySerializer.Serialize(stream, o);
        return stream.ToArray();
    }
}

Doesn’t look like much, but I’m sure we have all written something like this and paid it no mind. In fact, most of the time, code like this isn’t a problem.

This little method becomes a problem when that object o parameter is larger than 85k (actually 84,988 bytes) in contiguous memory. At that point, this object is considered to be a “large object.” That designation is significant since when you’re done with an object like this, the .Net garbage collector stores it on the Large Object Heap (LOH) rather than in the gen 0 heap.

A situation called LOH fragmentation arises when applications are frequently creating and disposing many large objects. A classic example is a file upload service that receives and processes large volumes of data in each request. The resulting fragmentation can lead to an OutOfMemoryException being thrown, even if the server still has plenty of memory and there’s plenty of space left in the process address space.

So, getting back to our little innocuous piece of code: we already know that if o is a large object, it will consume space in the LOH.… Read more

,