Skip to content
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Basics Update READMEs and samples for Xamarin Studio 5.7 Dec 2, 2014
SlappySalmon Update READMEs and samples for Xamarin Studio 5.7 Dec 2, 2014
Xamarin.Forms Update READMEs and samples for Xamarin Studio 5.7 Dec 2, 2014
.gitignore Initial sample sketches Oct 9, 2014
README.md Improve instructions for loading assemblies Jan 26, 2015

README.md

Xamarin Sample Sketches

Xamarin Sketches are a new interactive way to try out the C# language and the APIs provided by Xamarin. You can see results alongside each line of code, and even test UI code right in the simulator, all without even creating a project.

Sketches are still an early preview. Please see the documentation for install instructions and known issues and limitations.

This repository contains a few fun samples to demonstrate the power of interactive coding.

Loading Projects or Third-Party Assemblies

Call LoadAssembly (pathToAssembly) to bring any arbitrary library into the Sketch runtime. It is recommended to add the DLL as a resource to your sketch (see below), in which case you would call LoadAssembly (GetResourcePath ("some.dll")).

Loading Resources

You can bundle resources into your sketch, but there is currently no UI for it.

Create a folder next to your sketch file with a name like "mysketch.sketchcs.Resources", and any files placed within will be available for use in your code.

On iOS and Mac, they can be accessed through NSBundle.MainBundle, so you can use API like NSImage.ImageNamed(resourceName) and UIImage.FromBundle(resourceName).

There is also a more general method available on all platforms called GetResourcePath(resourceName). This is currently the only way to get access to bundled resources on Android.

See the samples in this repository for working examples.

Modifying Live UI

Please see the documentation for some examples. Sketches work by evaluating your code live in an "agent" app running on the target platform. Each app provides its own way to modify the UI:

  • Xamarin.iOS: A RootView static property is exposed to your Sketch. This is the UIView of the main UIViewController.
  • Xamarin.Forms (iOS and Android): A RootPage static property is exposed to your Sketch. This is a Xamarin.Forms.TabbedPage that is the main page of the app. You can add new Pages to RootPage.Children.
  • Xamarin.Android: A RootActivity static property is exposed to your Sketch. This represents the agent's running Activity.
  • Xamarin.Mac: A RootWindow static property is exposed to your Sketch. When accessed, an NSWindow will be created that lets you add views like RootWindow.ContentView.AddSubView(...).

For Xamarin.Android, the following convenience method is provided:

public static int DimToPixels (int dip, Android.Util.ComplexUnitType type = Android.Util.ComplexUnitType.Dip)
{
	return (int)Android.Util.TypedValue.ApplyDimension (
		type, dip, RootActivity.Resources.DisplayMetrics);
}

Reporting Issues

Please report issues in Xamarin bugzilla, or stop by our forums.

You can’t perform that action at this time.