Fix Editor events

This commit is contained in:
Frank A. Krueger 2017-11-26 12:18:33 -08:00
parent 8317b5244b
commit b670458687
3 changed files with 26 additions and 18 deletions

View File

@ -19,9 +19,9 @@ namespace Ooui.Forms.Renderers
if (disposing) { if (disposing) {
if (Control != null) { if (Control != null) {
Control.Changed -= HandleChanged; Control.Inputted -= HandleChanged;
//Control.Started -= OnStarted; //Control.Started -= OnStarted;
//Control.Ended -= OnEnded; Control.Changed -= OnEnded;
} }
} }
@ -40,9 +40,9 @@ namespace Ooui.Forms.Renderers
ClassName = "form-control" ClassName = "form-control"
}); });
Control.Changed += HandleChanged; Control.Inputted += HandleChanged;
//Control.Started += OnStarted; //Control.Started += OnStarted;
//Control.Ended += OnEnded; Control.Changed += OnEnded;
} }
UpdateText (); UpdateText ();
@ -75,13 +75,13 @@ namespace Ooui.Forms.Renderers
void HandleChanged (object sender, EventArgs e) void HandleChanged (object sender, EventArgs e)
{ {
ElementController.SetValueFromRenderer (Editor.TextProperty, Control.Text); ElementController.SetValueFromRenderer (Editor.TextProperty, Control.Value);
} }
void OnEnded (object sender, EventArgs eventArgs) void OnEnded (object sender, EventArgs eventArgs)
{ {
if (Control.Text != Element.Text) if (Control.Value != Element.Text)
ElementController.SetValueFromRenderer (Editor.TextProperty, Control.Text); ElementController.SetValueFromRenderer (Editor.TextProperty, Control.Value);
Element.SetValue (VisualElement.IsFocusedPropertyKey, false); Element.SetValue (VisualElement.IsFocusedPropertyKey, false);
ElementController.SendCompleted (); ElementController.SendCompleted ();
@ -108,8 +108,8 @@ namespace Ooui.Forms.Renderers
void UpdateText () void UpdateText ()
{ {
if (Control.Text != Element.Text) if (Control.Value != Element.Text)
Control.Text = Element.Text; Control.Value = Element.Text;
} }
void UpdateTextAlignment () void UpdateTextAlignment ()

View File

@ -42,12 +42,12 @@ namespace Ooui
public TextArea (string text) public TextArea (string text)
: this () : this ()
{ {
Text = text; Value = text;
} }
protected override bool TriggerEventFromMessage (Message message) protected override bool TriggerEventFromMessage (Message message)
{ {
if (message.TargetId == Id && message.MessageType == MessageType.Event && message.Key == "change") { if (message.TargetId == Id && message.MessageType == MessageType.Event && (message.Key == "change" || message.Key == "input")) {
// Don't need to notify here because the base implementation will fire the event // Don't need to notify here because the base implementation will fire the event
val = message.Value != null ? Convert.ToString (message.Value) : ""; val = message.Value != null ? Convert.ToString (message.Value) : "";
} }

View File

@ -29,11 +29,13 @@ namespace Samples
<Label Text=""Bottom Right"" Grid.Row=""1"" Grid.Column=""1"" /> <Label Text=""Bottom Right"" Grid.Row=""1"" Grid.Column=""1"" />
</Grid> </Grid>
</ContentView>"; </ContentView>";
editor.TextChanged += (sender, e) => DisplayXaml ();
DisplayXaml (); DisplayXaml ();
} }
public void DisplayXaml () public void DisplayXaml ()
{ {
try {
var asm = typeof (Xamarin.Forms.Xaml.Internals.XamlTypeResolver).Assembly; var asm = typeof (Xamarin.Forms.Xaml.Internals.XamlTypeResolver).Assembly;
var xamlLoaderType = asm.GetType ("Xamarin.Forms.Xaml.XamlLoader"); var xamlLoaderType = asm.GetType ("Xamarin.Forms.Xaml.XamlLoader");
var loadArgTypes = new[] { typeof (object), typeof (string) }; var loadArgTypes = new[] { typeof (object), typeof (string) };
@ -42,5 +44,11 @@ namespace Samples
loadMethod.Invoke (null, new object[] { contentView, editor.Text }); loadMethod.Invoke (null, new object[] { contentView, editor.Text });
results.Content = contentView; results.Content = contentView;
} }
catch (Exception ex) {
results.Content = new Label {
Text = ex.ToString (),
};
}
}
} }
} }