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";
|
2018-09-02 04:56:35 +00:00
|
|
|
|
public string Path => "/picker";
|
2018-03-20 03:01:51 +00:00
|
|
|
|
|
2018-09-02 04:56:35 +00:00
|
|
|
|
List<string> myItems = new List<string>
|
2018-03-20 03:01:51 +00:00
|
|
|
|
{
|
|
|
|
|
"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()
|
|
|
|
|
{
|
2023-03-17 08:08:32 +00:00
|
|
|
|
PageExtensions.Ui.Publish(Path, CreateElement);
|
2018-03-20 03:01:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|