Files
Common-VS2019/SacsMobileMaui/Maui/Controls/Panels/SamCheckBoxPanel.cs
T

83 lines
2.2 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
{
// --- 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(IsEnabled);
}
// --- 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; }
}
// --- Control events ---
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;
}
// --- The End ---
}
}