Created
May 21, 2016 07:38
-
-
Save ytabuchi/d7198cfe8661f8fe2247cad681cfd5e3 to your computer and use it in GitHub Desktop.
Xamarin Workbooks で Xamarin.Forms を表示、実行する md ファイルです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```json | |
{"exec-mode":"default","platform":"iOS","uti":"com.xamarin.workbook","packages":[{"id":"Xamarin.Forms","version":"2.2.0.31"}]} | |
``` | |
### Xamarin.Formsを Xamarin Workbooks で使うには? | |
File > Add Package から[Xamarin.Forms]を追加します。 | |
```csharp | |
#r "Xamarin.Forms.Platform.iOS" | |
#r "Xamarin.Forms.Core" | |
#r "Xamarin.Forms.Xaml" | |
#r "Xamarin.Forms.Platform" | |
``` | |
自動的に上記が追加されますので、C# コードを追加していきましょう。 | |
```csharp | |
using Xamarin.Forms; | |
using Xamarin.Forms.Platform.iOS; | |
``` | |
App.cs と適当なページを作成しましょう。 | |
```csharp | |
public class SamplePage : ContentPage | |
{ | |
public SamplePage() | |
{ | |
var label = new Label | |
{ | |
Text = "Hello Xamarin.Forms on Workbooks!", | |
VerticalOptions = LayoutOptions.Center, | |
HorizontalTextAlignment = TextAlignment.Center | |
}; | |
Content = label; | |
} | |
} | |
``` | |
```csharp | |
public class App : Application | |
{ | |
public App() | |
{ | |
MainPage = new NavigationPage(new SamplePage()); | |
} | |
} | |
``` | |
Workbooks で実行するには以下のおまじないを追加する必要があります。 | |
```csharp | |
Xamarin.Forms.Forms.Init(); | |
var a = new App(); | |
KeyWindow.RootViewController = a.MainPage.CreateViewController(); | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment