From 974f79cc5c887d717d93081fca5f155ce2b1ace9 Mon Sep 17 00:00:00 2001 From: Eilon Lipton Date: Fri, 24 Jan 2020 16:05:44 -0800 Subject: [PATCH] Fix VisualElement to have correct default values for properties Fixes #57 --- .../Elements/Handlers/VisualElementHandler.cs | 32 +++++++++---------- .../Elements/VisualElement.cs | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.MobileBlazorBindings/Elements/Handlers/VisualElementHandler.cs b/src/Microsoft.MobileBlazorBindings/Elements/Handlers/VisualElementHandler.cs index 9e823c71..b22796e1 100644 --- a/src/Microsoft.MobileBlazorBindings/Elements/Handlers/VisualElementHandler.cs +++ b/src/Microsoft.MobileBlazorBindings/Elements/Handlers/VisualElementHandler.cs @@ -45,37 +45,40 @@ public override void ApplyAttribute(ulong attributeEventHandlerId, string attrib switch (attributeName) { case nameof(XF.VisualElement.AnchorX): - VisualElementControl.AnchorX = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.AnchorX = AttributeHelper.StringToDouble((string)attributeValue, 0.50); break; case nameof(XF.VisualElement.AnchorY): - VisualElementControl.AnchorY = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.AnchorY = AttributeHelper.StringToDouble((string)attributeValue, 0.50); break; case nameof(XF.VisualElement.BackgroundColor): VisualElementControl.BackgroundColor = AttributeHelper.StringToColor((string)attributeValue); break; + case nameof(XF.VisualElement.FlowDirection): + VisualElementControl.FlowDirection = (XF.FlowDirection)AttributeHelper.GetInt(attributeValue); + break; case nameof(XF.VisualElement.HeightRequest): - VisualElementControl.HeightRequest = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.HeightRequest = AttributeHelper.StringToDouble((string)attributeValue, -1.00); break; case nameof(XF.VisualElement.InputTransparent): VisualElementControl.InputTransparent = AttributeHelper.GetBool(attributeValue); break; case nameof(XF.VisualElement.IsEnabled): - VisualElementControl.IsEnabled = AttributeHelper.GetBool(attributeValue); + VisualElementControl.IsEnabled = AttributeHelper.GetBool(attributeValue, true); break; case nameof(XF.VisualElement.IsTabStop): - VisualElementControl.IsTabStop = AttributeHelper.GetBool(attributeValue); + VisualElementControl.IsTabStop = AttributeHelper.GetBool(attributeValue, true); break; case nameof(XF.VisualElement.IsVisible): - VisualElementControl.IsVisible = AttributeHelper.GetBool(attributeValue); + VisualElementControl.IsVisible = AttributeHelper.GetBool(attributeValue, true); break; case nameof(XF.VisualElement.MinimumHeightRequest): - VisualElementControl.MinimumHeightRequest = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.MinimumHeightRequest = AttributeHelper.StringToDouble((string)attributeValue, -1.00); break; case nameof(XF.VisualElement.MinimumWidthRequest): - VisualElementControl.MinimumWidthRequest = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.MinimumWidthRequest = AttributeHelper.StringToDouble((string)attributeValue, -1.00); break; case nameof(XF.VisualElement.Opacity): - VisualElementControl.Opacity = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.Opacity = AttributeHelper.StringToDouble((string)attributeValue, 1.00); break; case nameof(XF.VisualElement.Rotation): VisualElementControl.Rotation = AttributeHelper.StringToDouble((string)attributeValue); @@ -87,13 +90,13 @@ public override void ApplyAttribute(ulong attributeEventHandlerId, string attrib VisualElementControl.RotationY = AttributeHelper.StringToDouble((string)attributeValue); break; case nameof(XF.VisualElement.Scale): - VisualElementControl.Scale = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.Scale = AttributeHelper.StringToDouble((string)attributeValue, 1.00); break; case nameof(XF.VisualElement.ScaleX): - VisualElementControl.ScaleX = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.ScaleX = AttributeHelper.StringToDouble((string)attributeValue, 1.00); break; case nameof(XF.VisualElement.ScaleY): - VisualElementControl.ScaleY = AttributeHelper.StringToDouble((string)attributeValue); + VisualElementControl.ScaleY = AttributeHelper.StringToDouble((string)attributeValue, 1.00); break; case nameof(XF.VisualElement.TabIndex): VisualElementControl.TabIndex = AttributeHelper.GetInt(attributeValue); @@ -105,10 +108,7 @@ public override void ApplyAttribute(ulong attributeEventHandlerId, string attrib VisualElementControl.TranslationY = AttributeHelper.StringToDouble((string)attributeValue); break; case nameof(XF.VisualElement.WidthRequest): - VisualElementControl.WidthRequest = AttributeHelper.StringToDouble((string)attributeValue); - break; - case nameof(XF.VisualElement.FlowDirection): - VisualElementControl.FlowDirection = (XF.FlowDirection)AttributeHelper.GetInt(attributeValue); + VisualElementControl.WidthRequest = AttributeHelper.StringToDouble((string)attributeValue, -1.00); break; case "onfocused": Renderer.RegisterEvent(attributeEventHandlerId, () => FocusedEventHandlerId = 0); diff --git a/src/Microsoft.MobileBlazorBindings/Elements/VisualElement.cs b/src/Microsoft.MobileBlazorBindings/Elements/VisualElement.cs index 4fb808b7..5a4165cc 100644 --- a/src/Microsoft.MobileBlazorBindings/Elements/VisualElement.cs +++ b/src/Microsoft.MobileBlazorBindings/Elements/VisualElement.cs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -using Microsoft.MobileBlazorBindings.Core; using Microsoft.AspNetCore.Components; -using XF = Xamarin.Forms; +using Microsoft.MobileBlazorBindings.Core; using Microsoft.MobileBlazorBindings.Elements.Handlers; +using XF = Xamarin.Forms; namespace Microsoft.MobileBlazorBindings.Elements {