78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Sarand.Net.Standard.Mobile.Forms.Controls
|
|
{
|
|
//=======================================================================
|
|
public class SaxEditor : Editor
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private bool trimTextOnCompletion = true;
|
|
private int NumberOfLinesPrevious = 0;
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SaxEditor ()
|
|
{
|
|
DefaultFontSize = FontSize;
|
|
Text = "";
|
|
TextChanged += SaxEditor_TextChanged;
|
|
Completed += SaxEditor_Completed;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
public double DefaultFontSize { get; }
|
|
public bool TrimText
|
|
{
|
|
get { return trimTextOnCompletion; }
|
|
set
|
|
{
|
|
if (trimTextOnCompletion == value) return;
|
|
trimTextOnCompletion = value;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l E v e n t s
|
|
//-------------------------------------------------------------------
|
|
// Key Press event is not supported directly in Xamarin.
|
|
// Requires O/S specific implementation.
|
|
// See: Sarand.LogisticsMgr.Mobile.Droid.Forms.Renderers.SlmEditorRenderer
|
|
public void OnKeyPress_Enter ()
|
|
{
|
|
// Resize control based on entered text.
|
|
InvalidateMeasure();
|
|
}
|
|
//-------------------------------------------------------------------
|
|
private void SaxEditor_TextChanged (object sender, TextChangedEventArgs e)
|
|
{
|
|
// If the number of lines of text has changed, resize the control.
|
|
int NumberOfLines = StringUtil.EmptyOnNull(Text).Split('\n').Length;
|
|
if (NumberOfLines != NumberOfLinesPrevious)
|
|
// Resize control based on entered text.
|
|
InvalidateMeasure();
|
|
NumberOfLinesPrevious = NumberOfLines;
|
|
}
|
|
private void SaxEditor_Completed (object sender, EventArgs e)
|
|
{
|
|
if (trimTextOnCompletion)
|
|
Text = Text.Trim();
|
|
// Resize control based on entered text.
|
|
InvalidateMeasure();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|