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

View File

@ -42,12 +42,12 @@ namespace Ooui
public TextArea (string text)
: this ()
{
Text = text;
Value = text;
}
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
val = message.Value != null ? Convert.ToString (message.Value) : "";
}

View File

@ -29,18 +29,26 @@ namespace Samples
<Label Text=""Bottom Right"" Grid.Row=""1"" Grid.Column=""1"" />
</Grid>
</ContentView>";
editor.TextChanged += (sender, e) => DisplayXaml ();
DisplayXaml ();
}
public void DisplayXaml ()
{
var asm = typeof (Xamarin.Forms.Xaml.Internals.XamlTypeResolver).Assembly;
var xamlLoaderType = asm.GetType ("Xamarin.Forms.Xaml.XamlLoader");
var loadArgTypes = new[] { typeof (object), typeof (string) };
var loadMethod = xamlLoaderType.GetMethod ("Load", System.Reflection.BindingFlags.Static|System.Reflection.BindingFlags.Public, null, System.Reflection.CallingConventions.Any, loadArgTypes, null);
var contentView = new ContentView ();
loadMethod.Invoke (null, new object[] { contentView, editor.Text });
results.Content = contentView;
try {
var asm = typeof (Xamarin.Forms.Xaml.Internals.XamlTypeResolver).Assembly;
var xamlLoaderType = asm.GetType ("Xamarin.Forms.Xaml.XamlLoader");
var loadArgTypes = new[] { typeof (object), typeof (string) };
var loadMethod = xamlLoaderType.GetMethod ("Load", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, System.Reflection.CallingConventions.Any, loadArgTypes, null);
var contentView = new ContentView ();
loadMethod.Invoke (null, new object[] { contentView, editor.Text });
results.Content = contentView;
}
catch (Exception ex) {
results.Content = new Label {
Text = ex.ToString (),
};
}
}
}
}