progress on XF picker.
This commit is contained in:
parent
50d6807a95
commit
091180ceeb
|
@ -16,6 +16,7 @@ using Xamarin.Forms;
|
|||
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
|
||||
[assembly: ExportRenderer (typeof (LinkLabel), typeof (LinkLabelRenderer))]
|
||||
[assembly: ExportRenderer (typeof (LinkView), typeof (LinkViewRenderer))]
|
||||
[assembly: ExportRenderer(typeof(Picker), typeof(PickerRenderer))]
|
||||
[assembly: ExportRenderer(typeof(ListView), typeof(ListViewRenderer))]
|
||||
[assembly: ExportRenderer (typeof (ProgressBar), typeof (ProgressBarRenderer))]
|
||||
[assembly: ExportRenderer (typeof (SearchBar), typeof (SearchBarRenderer))]
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
using Ooui.Forms.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Ooui.Forms.Renderers
|
||||
{
|
||||
public class PickerRenderer : ViewRenderer<Picker, Select>
|
||||
{
|
||||
private bool _disposed;
|
||||
private Select _select;
|
||||
|
||||
public PickerRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
|
||||
{
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
if (Control == null)
|
||||
{
|
||||
_select = new Select();
|
||||
_select.Change += _select_Change;
|
||||
|
||||
SetNativeControl(_select);
|
||||
}
|
||||
|
||||
UpdateItems();
|
||||
UpdateBackgroundColor();
|
||||
}
|
||||
|
||||
base.OnElementChanged(e);
|
||||
}
|
||||
|
||||
private void _select_Change(object sender, TargetEventArgs e)
|
||||
{
|
||||
Element.SetValueFromRenderer(Picker.SelectedIndexProperty, Element.ItemsSource.IndexOf(_select.Value));
|
||||
}
|
||||
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if (e.PropertyName == Picker.ItemsSourceProperty.PropertyName)
|
||||
{
|
||||
UpdateItems();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing && !_disposed)
|
||||
{
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateBackgroundColor()
|
||||
{
|
||||
var backgroundColor = Element.BackgroundColor.ToOouiColor();
|
||||
|
||||
_select.Style.BackgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
private void UpdateItems()
|
||||
{
|
||||
var items = Element.ItemsSource;
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var s = item.ToString();
|
||||
_select.AddOption(s, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue