Hi,
I want to show a picker after a buttonclick to change the color of a boxview. How can I show/hide a picker in a button click event? This is my code:
public partial class MainPage : ContentPage
{
public MainPage ()
{
InitializeComponent ();
}
Dictionary<string, Color> nameToColor = new Dictionary<string, Color>
{
{ "Aqua", Color.Aqua }, { "Black", Color.Black },
{ "Blue", Color.Blue }, { "Fuschia", Color.Fuschia },
{ "Gray", Color.Gray }, { "Green", Color.Green },
{ "Lime", Color.Lime }, { "Maroon", Color.Maroon },
{ "Navy", Color.Navy }, { "Olive", Color.Olive },
{ "Purple", Color.Purple }, { "Red", Color.Red },
{ "Silver", Color.Silver }, { "Teal", Color.Teal },
{ "White", Color.White }, { "Yellow", Color.Yellow }
};
private void ChangeColorButton_Click(object sender, EventArgs e)
{
_showColorPicker ();
}
private void _showColorPicker() {
Picker picker = new Picker
{
Title = "Color",
VerticalOptions = LayoutOptions.CenterAndExpand
};
foreach (string colorName in nameToColor.Keys)
{
picker.Items.Add(colorName);
}
picker.SelectedIndexChanged += (sender, args) =>
{
if (picker.SelectedIndex > -1)
{
string colorName = picker.Items[picker.SelectedIndex];
ColorBox.Color = nameToColor[colorName];
}
};
}
}