Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CharEditorControl.cs « Controls « Xamarin.PropertyEditing.Mac - github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f68457dd70e394b667b6ea03e6324273e59b0aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using Xamarin.PropertyEditing.ViewModels;

namespace Xamarin.PropertyEditing.Mac
{
	internal class CharEditorControl
		: EntryPropertyEditor<char>
	{
		public CharEditorControl (IHostResourceProvider hostResources)
			: base (hostResources)
		{
		}

		protected override EntryPropertyEditorDelegate<char> CreateDelegate (PropertyViewModel<char> viewModel)
		{
			return new CharDelegate (viewModel);
		}

		protected override void UpdateAccessibilityValues ()
		{
			base.UpdateAccessibilityValues ();
			Entry.AccessibilityTitle = string.Format (Properties.Resources.AccessibilityChar, ViewModel.Property.Name);
		}

		protected override string GetValue (char value)
		{
			return (value == default (char)) ? null : value.ToString();
		}

		private class CharDelegate
			: EntryPropertyEditorDelegate<char>
		{
			public CharDelegate (PropertyViewModel<char> viewModel)
				: base (viewModel)
			{
			}

			protected override char GetValue (string value)
			{
				return (String.IsNullOrEmpty (value) ? default (char) : value[0]);
			}

			protected override bool CanGetValue (string value)
			{
				return Char.TryParse (value, out _);
			}
		}
	}
}