chovy-sign/ChovySign-GUI/Global/LabeledTextBox.axaml.cs

105 lines
2.2 KiB
C#
Raw Normal View History

2023-04-24 23:16:52 +00:00
using Avalonia;
using Avalonia.Controls;
2023-04-22 03:54:29 +00:00
using Avalonia.Input;
2023-04-24 23:16:52 +00:00
using Avalonia.Interactivity;
2023-04-22 03:54:29 +00:00
using System;
using System.Text;
2023-04-25 02:22:34 +00:00
using System.Threading;
using System.Threading.Tasks;
2023-04-21 06:21:21 +00:00
namespace ChovySign_GUI.Global
{
2023-04-25 02:22:34 +00:00
2023-04-21 06:21:21 +00:00
public partial class LabeledTextBox : UserControl
{
2023-04-23 08:15:11 +00:00
public event EventHandler<EventArgs>? TextChanged;
2023-04-22 03:54:29 +00:00
protected virtual void OnTextChanged(EventArgs e)
{
if (TextChanged is not null)
TextChanged(this, e);
}
public int MaxLength
{
get
{
return this.txtBox.MaxLength;
}
set
{
this.txtBox.MaxLength = value;
}
}
public bool Password
{
get
{
2023-04-25 02:22:34 +00:00
return this.txtBox.Password;
2023-04-22 03:54:29 +00:00
}
set
{
2023-04-25 02:22:34 +00:00
this.txtBox.Password = value;
2023-04-21 06:21:21 +00:00
}
}
public string Watermark
{
get
{
return this.txtBox.Watermark;
}
set
{
this.txtBox.Watermark = value;
}
}
2023-04-24 23:16:52 +00:00
public string? AllowedChars
2023-04-22 03:54:29 +00:00
{
get
{
2023-04-25 02:22:34 +00:00
return this.txtBox.AllowedChars;
2023-04-22 03:54:29 +00:00
}
set
{
2023-04-25 02:22:34 +00:00
this.txtBox.AllowedChars = value;
2023-04-22 03:54:29 +00:00
}
}
2023-04-21 06:21:21 +00:00
public string Text
{
get
{
return this.txtBox.Text;
}
set
{
this.txtBox.Text = value;
}
}
2023-04-25 02:22:34 +00:00
public string Label
2023-04-24 23:16:52 +00:00
{
2023-04-25 02:22:34 +00:00
get
2023-04-24 23:16:52 +00:00
{
2023-04-25 02:22:34 +00:00
string? lbl = this.lblTxt.Content as string;
if (lbl is null) return "";
else return lbl;
2023-04-24 23:16:52 +00:00
}
2023-04-25 02:22:34 +00:00
set
2023-04-24 23:16:52 +00:00
{
2023-04-25 02:22:34 +00:00
this.lblTxt.Content = value;
2023-04-24 23:16:52 +00:00
}
2023-04-22 03:54:29 +00:00
}
2023-04-25 02:22:34 +00:00
public LabeledTextBox()
2023-04-22 03:54:29 +00:00
{
2023-04-25 02:22:34 +00:00
InitializeComponent();
this.txtBox.TextChanged += onTxtBoxTextChange;
2023-04-24 23:16:52 +00:00
}
2023-04-25 02:22:34 +00:00
private void onTxtBoxTextChange(object? sender, EventArgs e)
{
OnTextChanged(e);
2023-04-21 06:21:21 +00:00
}
}
}