Ooui-tws-port/Samples/PickerSample.cs

76 lines
1.7 KiB
C#
Raw Normal View History

2018-03-20 03:01:51 +00:00
using Ooui;
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace Samples
{
public class PickerSample : ISample
{
private Xamarin.Forms.Label _label;
private Xamarin.Forms.Picker _picker;
public string Title => "Xamarin.Forms Picker Sample";
List<string> myItems = new List<string>
{
"red",
"green",
"yellow",
"blue",
"white",
"black",
"purple",
"orange",
};
public Ooui.Element CreateElement()
{
var panel = new StackLayout();
var titleLabel = new Xamarin.Forms.Label
{
Text = "Picker",
FontSize = 24,
FontAttributes = FontAttributes.Bold
};
panel.Children.Add(titleLabel);
_picker = new Picker
{
Title = "Hello",
//VerticalOptions = LayoutOptions.CenterAndExpand,
ItemsSource = myItems,
};
panel.Children.Add(_picker);
_picker.SelectedIndexChanged += OnPickerValueChanged;
_label = new Xamarin.Forms.Label
{
Text = "Picker value is",
HorizontalOptions = LayoutOptions.Center
};
panel.Children.Add(_label);
var page = new ContentPage
{
Content = panel
};
return page.GetOouiElement();
}
void OnPickerValueChanged(object sender, EventArgs e)
{
_label.Text = String.Format("Picker value is {0} ({1})", _picker.SelectedIndex, myItems[_picker.SelectedIndex]);
}
public void Publish()
{
UI.Publish("/picker", CreateElement);
}
}
}