Dynamic view gallery support all Enum properties (#6434)

This commit is contained in:
Pavel Yakovlev 2019-06-19 11:45:54 -07:00 коммит произвёл Rui Marinho
Родитель 1f7f8a2c00
Коммит 95786cd309
1 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -165,9 +165,9 @@ namespace Xamarin.Forms.Controls
{
propertyLayout.Children.Add(CreateThicknessPicker(property, element));
}
else if (property.PropertyType == typeof(TextAlignment))
else if (property.PropertyType.IsEnum)
{
propertyLayout.Children.Add(CreateEnumPicker(property, element, typeof(TextAlignment)));
propertyLayout.Children.Add(CreateEnumPicker(property, element));
}
else
{
@ -325,7 +325,7 @@ namespace Xamarin.Forms.Controls
return actions;
}
static Grid CreateEnumPicker(PropertyInfo property, BindableObject element, Type elementType)
static Grid CreateEnumPicker(PropertyInfo property, BindableObject element)
{
var grid = new Grid
{
@ -339,10 +339,11 @@ namespace Xamarin.Forms.Controls
},
};
grid.AddChild(new Label { Text = property.Name, FontAttributes = FontAttributes.Bold }, 0, 0);
var picker = new Picker { Title = property.Name };
var elementType = property.PropertyType;
var picker = new Picker();
foreach (var item in Enum.GetNames(elementType))
picker.Items.Add(item);
picker.SelectedItem = property.GetValue(element).ToString();
grid.AddChild(picker, 1, 0);
picker.SelectedIndexChanged += (_, e) =>
@ -355,7 +356,7 @@ namespace Xamarin.Forms.Controls
if (e.PropertyName == property.Name)
{
var newVal = property.GetValue(element);
if (newVal.ToString() != picker.SelectedItem.ToString())
if (newVal.ToString() != picker.SelectedItem?.ToString())
picker.SelectedItem = newVal;
}
};