71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Billing.UI
|
|
{
|
|
public class SegmentedControl : View, IViewContainer<SegmentedControlOption>
|
|
{
|
|
public IList<SegmentedControlOption> Children { get; set; }
|
|
|
|
public SegmentedControl()
|
|
{
|
|
Children = new List<SegmentedControlOption>();
|
|
}
|
|
|
|
public static readonly BindableProperty TintColorProperty = Helper.Create<Color, SegmentedControl>(nameof(TintColor));
|
|
public static readonly BindableProperty DisabledColorProperty = Helper.Create<Color, SegmentedControl>(nameof(DisabledColor));
|
|
public static readonly BindableProperty SelectedTextColorProperty = Helper.Create<Color, SegmentedControl>(nameof(SelectedTextColor));
|
|
public static readonly BindableProperty SelectedSegmentIndexProperty = Helper.Create<int, SegmentedControl>(nameof(SelectedSegmentIndex));
|
|
|
|
public Color TintColor
|
|
{
|
|
get => (Color)GetValue(TintColorProperty);
|
|
set => SetValue(TintColorProperty, value);
|
|
}
|
|
public Color DisabledColor
|
|
{
|
|
get => (Color)GetValue(DisabledColorProperty);
|
|
set => SetValue(DisabledColorProperty, value);
|
|
}
|
|
public Color SelectedTextColor
|
|
{
|
|
get => (Color)GetValue(SelectedTextColorProperty);
|
|
set => SetValue(SelectedTextColorProperty, value);
|
|
}
|
|
public int SelectedSegmentIndex
|
|
{
|
|
get => (int)GetValue(SelectedSegmentIndexProperty);
|
|
set => SetValue(SelectedSegmentIndexProperty, value);
|
|
}
|
|
|
|
public SegmentedControlOption SelectedSegment => Children[SelectedSegmentIndex];
|
|
|
|
public event EventHandler<ValueChangedEventArgs> ValueChanged;
|
|
|
|
//[EditorBrowsable(EditorBrowsableState.Never)]
|
|
public void SendValueChanged()
|
|
{
|
|
ValueChanged?.Invoke(this, new ValueChangedEventArgs { NewValue = SelectedSegmentIndex });
|
|
}
|
|
}
|
|
|
|
public class SegmentedControlOption : View
|
|
{
|
|
public static readonly BindableProperty TextProperty = Helper.Create<string, SegmentedControlOption>(nameof(Text));
|
|
|
|
public string Text
|
|
{
|
|
get => (string)GetValue(TextProperty);
|
|
set => SetValue(TextProperty, value);
|
|
}
|
|
|
|
public object Value { get; set; }
|
|
}
|
|
|
|
public class ValueChangedEventArgs : EventArgs
|
|
{
|
|
public int NewValue { get; set; }
|
|
}
|
|
}
|