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

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2019-09-04 20:50:36 +0300
committerEric Maupin <ermaup@microsoft.com>2019-10-04 23:19:09 +0300
commit655e2775af7ebe30ed38522c9ec8bc7242244a31 (patch)
treebc055afff31245e1335208596bb896bcbbab3dae /Xamarin.PropertyEditing
parent5d9c94157b17afa8f1174392626e7c193a6cb491 (diff)
[Core] AutoResizingPropertyViewModel
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r--Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs99
-rw-r--r--Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs1
2 files changed, 100 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs
new file mode 100644
index 0000000..43e965d
--- /dev/null
+++ b/Xamarin.PropertyEditing/ViewModels/AutoResizingPropertyViewModel.cs
@@ -0,0 +1,99 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using Xamarin.PropertyEditing.Common;
+
+namespace Xamarin.PropertyEditing.ViewModels
+{
+ internal class AutoResizingPropertyViewModel
+ : PropertyViewModel<AutoResizingFlags>
+ {
+ public AutoResizingPropertyViewModel (TargetPlatform platform, IPropertyInfo property, IEnumerable<IObjectEditor> editors, PropertyVariation variation = null)
+ : base (platform, property, editors, variation)
+ {
+ ToggleMaskCommand = new RelayCommand<AutoResizingFlags> (ToggleFlag);
+ CycleSizingCommand = new RelayCommand (OnCycleSizing);
+ }
+
+ public ICommand ToggleMaskCommand
+ {
+ get;
+ }
+
+ public ICommand CycleSizingCommand
+ {
+ get;
+ }
+
+ public bool LeftMarginFixed
+ {
+ get => (Value & AutoResizingFlags.FlexibleLeftMargin) != AutoResizingFlags.FlexibleLeftMargin;
+ set => SetFlag (AutoResizingFlags.FlexibleLeftMargin, !value);
+ }
+
+ public bool RightMarginFixed
+ {
+ get => (Value & AutoResizingFlags.FlexibleRightMargin) != AutoResizingFlags.FlexibleRightMargin;
+ set => SetFlag (AutoResizingFlags.FlexibleRightMargin, !value);
+ }
+
+ public bool TopMarginFixed
+ {
+ get => (Value & AutoResizingFlags.FlexibleTopMargin) != AutoResizingFlags.FlexibleTopMargin;
+ set => SetFlag (AutoResizingFlags.FlexibleTopMargin, !value);
+ }
+
+ public bool BottomMarginFixed
+ {
+ get => (Value & AutoResizingFlags.FlexibleBottomMargin) != AutoResizingFlags.FlexibleBottomMargin;
+ set => SetFlag (AutoResizingFlags.FlexibleBottomMargin, !value);
+ }
+
+ public bool HeightSizable
+ {
+ get => (Value & AutoResizingFlags.FlexibleHeight) == AutoResizingFlags.FlexibleHeight;
+ set => SetFlag (AutoResizingFlags.FlexibleHeight, value);
+ }
+
+ public bool WidthSizable
+ {
+ get => (Value & AutoResizingFlags.FlexibleWidth) == AutoResizingFlags.FlexibleWidth;
+ set => SetFlag (AutoResizingFlags.FlexibleWidth, value);
+ }
+
+ protected override void OnValueChanged ()
+ {
+ base.OnValueChanged ();
+
+ OnPropertyChanged (nameof(LeftMarginFixed));
+ OnPropertyChanged (nameof(RightMarginFixed));
+ OnPropertyChanged (nameof(TopMarginFixed));
+ OnPropertyChanged (nameof(BottomMarginFixed));
+ OnPropertyChanged (nameof(HeightSizable));
+ OnPropertyChanged (nameof(WidthSizable));
+ }
+
+ private void SetFlag (AutoResizingFlags flag, bool set)
+ {
+ Value = (set) ? Value | flag : Value & ~flag;
+ }
+
+ private void ToggleFlag (AutoResizingFlags flag)
+ {
+ Value = Value ^ flag;
+ }
+
+ private void OnCycleSizing ()
+ {
+ if (!WidthSizable && !HeightSizable) {
+ WidthSizable = true;
+ } else if (WidthSizable && !HeightSizable) {
+ HeightSizable = true;
+ } else if (WidthSizable && HeightSizable) {
+ WidthSizable = false;
+ } else if (!WidthSizable && HeightSizable) {
+ HeightSizable = false;
+ }
+ }
+ }
+}
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
index 8e5cceb..5862ad9 100644
--- a/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/PropertiesViewModel.cs
@@ -655,6 +655,7 @@ namespace Xamarin.PropertyEditing.ViewModels
{ typeof(object), (tp,p,e,v) => new ObjectPropertyViewModel (tp, p, e, v) },
{ typeof(ITypeInfo), (tp,p,e,v) => new TypePropertyViewModel (tp, p, e, v) },
{ typeof(CommonRatio), (tp, p, e, v) => new RatioViewModel (tp, p, e, v) },
+ { typeof(AutoResizingFlags), (tp, p, e, v) => new AutoResizingPropertyViewModel (tp, p, e, v) },
};
}
}