Since Microsoft announced that they’d be bringing Visual Studio to Mac a weeks ago, we’ve taken some time to put Xuni through its paces. It's definitely exciting for us (and many others) to be able to use a version of Visual Studio on Mac OS. While the experience is mostly similar to Xamarin Studio, it's worth walking through the setup process for using Xuni in the new IDE for those who wanted to give it a try. In this example, we'll walk through adding a radial gauge to simple Xamarin.Forms app in Visual Studio for Mac.

Getting Started

If you're completely starting from scratch, you can download the Visual Studio for Mac preview from Microsoft here. The installer should take care of setting up Xamarin for you. You can download Xuni right here, or you can simply connect to one of the NuGet feeds so that it's available to use in your app (more on that later). Note: Visual Studio for Mac currently uses an alpha version of Mono so be mindful of updates to Xamarin in Xamarin Studio if you're trying to use them side-by-side. Once you have Visual Studio for Mac installed, create a new Xamarin.Forms project by choosing Forms App template from the Multiplatform tab. CreateProject We'll name this sample FirstXuniApp as we set up the template, and choose to use a Portable Class Library that targets both iOS and Android. Though we're sticking with a basic Xamarin.Forms template, you'll notice that there are also some other new templates available in the IDE using .NET Core. Once we've finished making our way through the New Project options we'll need to add Xuni to our project. We generally keep the most recent major version of Xuni available on nuget.org, but we also maintain our own private nuget server where we occasionally push hotfixes in between major releases. If you wish to connect to this server you can add it as an additional NuGet source in Visual Studio. To do this:

  1. Double click on the packages folder or Right Click it and select Add Packages...
  2. Select Configure Sources... from the dropdown in the top left of the Add Packages dialog
  3. Click the Add button to add a new package source
  4. Name your source GrapeCity and configure the location to be http://nuget.grapecity.com/nuget

nugetsource Now you'll be able to add Xuni controls to your project. Simply choose the source your interested in using (whether nuget.org or GrapeCity) and add the packages to your project. For this example, we'll add a radial gauge to our projects by adding the Xuni.Forms.Gauge package to each project. nugetpackages To add the radial gauge to our xaml we will need to make a few additons. First, we'll need to add the xuni namespace to our Xaml before we can interact with it. Once we've done that, we can add a radial gauge and set a few properties as shown below in the complete Xaml.


<?xml version="1.0" encoding="utf-8"?>  
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"  
xmlns:xuni="clr-namespace:Xuni.Forms.Gauge;assembly=Xuni.Forms.Gauge"  
xmlns:local="clr-namespace:FirstXuniApp" x:Class="FirstXuniApp.FirstXuniAppPage">  
<StackLayout VerticalOptions="CenterAndExpand">  
<xuni:XuniRadialGauge x:Name="Radial" Value="75" Min="0" Max="100" StartAngle="-45" SweepAngle="270"/>  
</StackLayout>  
</ContentPage>  

We'll also need to make a few additions to the AppDelegate.cs file so that the radial gauge renders correctly on iOS. We'll add a couple lines to initialize the renderer for the radial gauge control and ensure that it's linked properly when deployed to a device.


static Xuni.Forms.Gauge.Platform.iOS.RadialGaugeRenderer radDummy;  
public override bool FinishedLaunching(UIApplication app, NSDictionary options)  
{  
global::Xamarin.Forms.Forms.Init();  

LoadApplication(new App());  
Xuni.Forms.Gauge.Platform.iOS.Forms.Init();  
return base.FinishedLaunching(app, options);  
}  

The final piece of the sample app is to add a runtime license to our project for Xuni. All of the Xuni controls contain runtime license validation for each app. You can generate runtime keys on componentone.com or goxuni.com (including a free 30 day evaluation key if you don't own a license). To generate a runtime key for your app:

  1. Log in to www.goxuni.com. If you don’t have an account, you can create one.
  2. Click License Your App. This link can also be found in the Support menu.
  3. Select Evaluation or Full, depending on the type of key you’re generating.
  4. Select C# and enter the name of your app, which should be the same as the default namespace. In our sample it's FirstXuniApp
  5. Click generate.

Take this key and copy it into your project. The simplest way to do this is to create a new class named License.cs. The text output from the website includes the static class declaration so it’s simple to paste this into Visual Studio for Mac. Finally you need to set the LicenseManager to you key before you initialize the Xuni control The easiest place to do this is in the constructor for the App class.


public App()  
{  
InitializeComponent();  
Xuni.Forms.Core.LicenseManager.Key = License.Key;  
MainPage = new FirstXuniAppPage();  
}  

Now you'll be able to run your radial gauge app. RadialGauge

Final thoughts

Using Xuni with Visual Studio for Mac is just as easy as using it with Xamarin Studio. As Microsoft continues to develop the IDE, we'll continue to see exciting new developments for the Xamarin platform.