Ooui-tws-port/Samples/SwitchErrorSample.cs

42 lines
1.1 KiB
C#
Raw Normal View History

2018-02-02 07:14:07 +00:00
using Ooui;
using Xamarin.Forms;
namespace Samples
{
// From https://github.com/praeclarum/Ooui/issues/48
public class SwitchErrorSample : ISample
{
public string Title => "Xamarin.Forms Switch Error";
2018-09-02 04:56:35 +00:00
public string Path => "/switch";
2018-02-02 07:14:07 +00:00
public Ooui.Element CreateElement ()
{
var layout = new StackLayout();
var label = new Xamarin.Forms.Label
{
Text = "Switch state goes here",
HorizontalTextAlignment = TextAlignment.Center
};
var sw = new Switch
{
HorizontalOptions = LayoutOptions.CenterAndExpand
};
sw.Toggled += (sender, args) =>
{
2018-02-03 04:51:05 +00:00
label.Text = $"Switch state is: {((Switch)sender).IsToggled}";
2018-02-02 07:14:07 +00:00
};
layout.Children.Add(label);
layout.Children.Add(sw);
return new ContentPage
{
Content = layout
}.GetOouiElement();
}
public void Publish()
{
2018-09-02 04:56:35 +00:00
UI.Publish (Path, CreateElement);
2018-02-02 07:14:07 +00:00
}
}
}