From dae033d06b33edccd61b913c0d163e2d652a445a Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 27 Sep 2013 12:35:42 -0700 Subject: [PATCH] Give some usage examples --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/README.md b/README.md index 2f2f0f9..6e9bf75 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,50 @@ Splat currently supports: additional extension methods to make using them easier. * A way to detect whether you're in a Unit Test runner / Design Mode +### Cross-platform Image Loading + +```cs +// +// Load an Image +// This code even works in a Portable Library +// + +var wc = new WebClient(); +var imageBytes = await wc.DownloadDataTaskAsync("http://octodex.github.com/images/Professortocat_v2.png"); +ProfileImage = await BitmapLoader.Current.Load(imageBytes, null /* Use original width */, null /* Use original height */); + +``` + +Then later, in your View: + +``` +ImageView.Source = ViewModel.ProfileImage.ToNative(); +``` + +### Using Cross-Platform Colors and Geometry + +```cs +// This System.Drawing class works, even on WinRT or WP8 where it's not supposed to exist +// Also, this works in a Portable Library, in your ViewModel +ProfileBackgroundAccentColor = new Color(255, 255, 255, 255); +``` + +Later, in the view, we can use it: + +``` +ImageView.Background = ViewModel.ProfileBackgroundAccentColor.ToNativeBrush(); +``` + +### Detecting whether you're in a unit test runner + +```cs +// If true, we are running unit tests +ModeDetector.InUnitTestRunner(); + +// If true, we are running inside Blend, so don't do anything +ModeDetector.InDesignMode(); +``` + ### How do I install? [Always Be NuGetting](https://nuget.org/packages/Splat/). Package contains binaries for: