148 lines
4.9 KiB
C#
148 lines
4.9 KiB
C#
using Sarand.Net.Mobile.Maui.Controls.Views;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sarand.Net.Mobile.Maui.Controls.Panels
|
|
{
|
|
//=======================================================================
|
|
public class SamCheckBoxPanel : SamControlPanel
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private readonly SamCheckBox checkbox = new SamCheckBox() { };
|
|
private readonly TapGestureRecognizer gestureSuffixTap = new TapGestureRecognizer() { };
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SamCheckBoxPanel()
|
|
{
|
|
// View configuration.
|
|
HorizontalOptions = LayoutOptions.Start;
|
|
|
|
// Control configuration.
|
|
BorderThickness = 0;
|
|
BorderColor = Colors.Transparent;
|
|
BackgroundColor = Colors.Transparent;
|
|
|
|
// Checkbox events.
|
|
checkbox.Focused += Entry_Focused;
|
|
checkbox.Unfocused += Entry_Unfocused;
|
|
checkbox.CheckedChanged += Checkbox_CheckedChanged;
|
|
gestureSuffixTap.Tapped += GestureSuffixTap_Tapped;
|
|
LabelSuffix.GestureRecognizers.Add(gestureSuffixTap);
|
|
|
|
ConfigureComponents();
|
|
SetControlActivity();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
protected override View ControlView { get { return checkbox; } }
|
|
public bool IsChecked
|
|
{
|
|
get { return checkbox.IsChecked; }
|
|
set { if (checkbox.IsChecked == value) return; checkbox.IsChecked = value; }
|
|
}
|
|
public new LayoutOptions HorizontalOptions
|
|
{
|
|
get { return checkbox.HorizontalOptions; }
|
|
set { checkbox.HorizontalOptions = value; ReadOnlyLabel.HorizontalOptions = checkbox.HorizontalOptions; }
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n f i g u r e C o m p o n e n t s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>Control configuration that can be changed dynamically.</summary>
|
|
public override void ConfigureComponents()
|
|
{
|
|
base.ConfigureComponents();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l A c t i v i t y
|
|
//-------------------------------------------------------------------
|
|
public override void SetControlActivity()
|
|
{
|
|
base.SetControlActivity();
|
|
SetControlsReadOnly();
|
|
}
|
|
public override void SetControlsReadOnly()
|
|
{
|
|
base.SetControlsReadOnly();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l E v e n t s
|
|
//-------------------------------------------------------------------
|
|
private void Entry_Focused(object? sender, FocusEventArgs e)
|
|
{
|
|
Control_Focused(sender, e);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
private void Entry_Unfocused(object? sender, FocusEventArgs e)
|
|
{
|
|
Control_Unfocused(sender, e);
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// Checked changed.
|
|
public event EventHandler<CheckedChangedEventArgs>? CheckedChanged;
|
|
private void Checkbox_CheckedChanged(object? sender, CheckedChangedEventArgs e)
|
|
{
|
|
ReadOnlyText = checkbox.IsChecked ? "X" : "";
|
|
if (ReadOnly) return;
|
|
if (CheckedChanged != null) CheckedChanged.Invoke(sender, e);
|
|
}
|
|
|
|
private void GestureSuffixTap_Tapped(object? sender, TappedEventArgs e)
|
|
{
|
|
checkbox.IsChecked = !checkbox.IsChecked;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// V i e w E v e n t s
|
|
//-------------------------------------------------------------------
|
|
protected override void OnParentSet()
|
|
{
|
|
base.OnParentSet();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
protected override void OnPropertyChanging([CallerMemberName] string propertyName = "")
|
|
{
|
|
base.OnPropertyChanging(propertyName);
|
|
}
|
|
protected override void OnPropertyChanged([CallerMemberName] string propertyName = "")
|
|
{
|
|
base.OnPropertyChanged(propertyName);
|
|
//Logger.Debug(GetType().Name + ".OnPropertyChanged Name=" + propertyName);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
protected override void OnChildAdded(Element child)
|
|
{
|
|
base.OnChildAdded(child);
|
|
}
|
|
protected override void OnChildRemoved(Element child, int oldLogicalIndex)
|
|
{
|
|
base.OnChildRemoved(child, oldLogicalIndex);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
protected override void OnSizeAllocated(double width, double height)
|
|
{
|
|
base.OnSizeAllocated(width, height);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|