Fix Entry

This commit is contained in:
Frank A. Krueger 2017-11-26 08:12:28 -08:00
parent e085f236b6
commit 786343a8ae
3 changed files with 14 additions and 11 deletions

View File

@ -7,6 +7,7 @@ using Xamarin.Forms.Internals;
[assembly: Dependency (typeof (ResourcesProvider))] [assembly: Dependency (typeof (ResourcesProvider))]
[assembly: ExportRenderer (typeof (BoxView), typeof (BoxRenderer))] [assembly: ExportRenderer (typeof (BoxView), typeof (BoxRenderer))]
[assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))] [assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))]
[assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))]
[assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))] [assembly: ExportRenderer (typeof (Label), typeof (LabelRenderer))]
namespace Ooui.Forms namespace Ooui.Forms

View File

@ -13,17 +13,15 @@ namespace Ooui.Forms.Renderers
static Size initialSize = Size.Zero; static Size initialSize = Size.Zero;
public EntryRenderer () IElementController ElementController => Element as IElementController;
{
}
public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint) public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint)
{ {
return base.GetDesiredSize (widthConstraint, heightConstraint); var size = Element.Text.MeasureSize (Element.FontFamily, Element.FontSize, Element.FontAttributes);
size = new Size (size.Width, size.Height * 1.428 + 14);
return new SizeRequest (size, size);
} }
IElementController ElementController => Element as IElementController;
protected override void Dispose (bool disposing) protected override void Dispose (bool disposing)
{ {
if (_disposed) if (_disposed)
@ -53,6 +51,10 @@ namespace Ooui.Forms.Renderers
var textField = new Ooui.Input (InputType.Text); var textField = new Ooui.Input (InputType.Text);
SetNativeControl (textField); SetNativeControl (textField);
Debug.Assert (Control != null, "Control != null");
textField.ClassName = "form-control";
_defaultTextColor = Colors.Black; _defaultTextColor = Colors.Black;
textField.Inputted += OnEditingChanged; textField.Inputted += OnEditingChanged;
@ -154,14 +156,14 @@ namespace Ooui.Forms.Renderers
void UpdatePlaceholder () void UpdatePlaceholder ()
{ {
Control.Placeholder = Element.Placeholder; Control.Placeholder = Element.Placeholder ?? "";
} }
void UpdateText () void UpdateText ()
{ {
// ReSharper disable once RedundantCheckBeforeAssignment // ReSharper disable once RedundantCheckBeforeAssignment
if (Control.Text != Element.Text) if (Control.Value != Element.Text)
Control.Text = Element.Text; Control.Value = Element.Text;
} }
} }
} }

View File

@ -4,8 +4,8 @@
x:Class="ButtonXaml.ButtonXamlPage"> x:Class="ButtonXaml.ButtonXamlPage">
<StackLayout Padding="20"> <StackLayout Padding="20">
<Label Text="Welcome to Xamarin.Forms!"/> <Label Text="Welcome to Xamarin.Forms!" FontSize="32" FontAttributes="Bold" />
<Label x:Name="LabelCount" Text="Click Count: 0"/> <Entry x:Name="LabelCount" Text="Click Count: 0"/>
<Button Text="Tap for click count!" <Button Text="Tap for click count!"
Clicked="OnButtonClicked" /> Clicked="OnButtonClicked" />
</StackLayout> </StackLayout>