public void FocusEventAndSourceName() { TextBox control = new TextBox(); TestControl controlWithEvent = new TestControl() { Name = "controlWithEvent" }; FocusBehavior behavior = new FocusBehavior() { EventName = "TestEvent", SourceName = "controlWithEvent" }; Interaction.GetBehaviors(control).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); grid.Children.Add(new Button()); grid.Children.Add(control); grid.Children.Add(new Button()); grid.Children.Add(controlWithEvent); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(control); controlWithEvent.RaiseTestEvent(); CheckFocusedElement(control); }); EnqueueTestComplete(); }
public void FocusPropertyNameSourceName() { TextBox control = new TextBox(); TestControl controlWithProperty = new TestControl() { Name = "controlWithProperty" }; FocusBehavior behavior = new FocusBehavior() { PropertyName = "TestProperty_1", SourceName = "controlWithProperty" }; Interaction.GetBehaviors(control).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); Button button = new Button(); grid.Children.Add(button); grid.Children.Add(control); grid.Children.Add(controlWithProperty); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(control); controlWithProperty.TestProperty_1 = "Test"; CheckFocusedElement(control); }); EnqueueTestComplete(); }
public void DefalutValues() { FocusBehavior behavior = new FocusBehavior(); Assert.AreEqual(TimeSpan.FromMilliseconds(0), FocusBehavior.DefaultFocusDelay); Assert.AreEqual(null, behavior.FocusDelay); Assert.AreEqual("Loaded", behavior.EventName); }
public void DefalutValues() { FocusBehavior behavior = new FocusBehavior(); #if !SILVERLIGHT Assert.AreEqual(TimeSpan.FromMilliseconds(0), FocusBehavior.DefaultFocusDelay); #else Assert.AreEqual(TimeSpan.FromMilliseconds(500), FocusBehavior.DefaultFocusDelay); #endif Assert.AreEqual(null, behavior.FocusDelay); Assert.AreEqual("Loaded", behavior.EventName); }
/// <summary> /// Focus behavior for input component with optional behaviors. /// </summary> /// <param name="behavior">enum: AntDesign.FocusBehavior</param> /// <param name="preventScroll">When true, element receiving focus will not be scrolled to.</param> public virtual async Task Focus(FocusBehavior behavior = default, bool preventScroll = false) { if (behavior == FocusBehavior.FocusAndClear) { await Clear(); StateHasChanged(); } else { await FocusAsync(Ref, behavior, preventScroll); IsFocused = true; } }
private static void OnApplyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { var behaviors = Interaction.GetBehaviors(sender); // Remove the existing behavior instances foreach (var old in behaviors.OfType <FocusBehavior>().ToArray()) { behaviors.Remove(old); } if ((bool)args.NewValue) { // Creates a new behavior and attaches to the target var behavior = new FocusBehavior(); // Apply the behavior behaviors.Add(behavior); } }
public void FocusOnLoaded() { TextBox control = new TextBox(); FocusBehavior behavior = new FocusBehavior(); Interaction.GetBehaviors(control).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); grid.Children.Add(new Button()); grid.Children.Add(control); grid.Children.Add(new Button()); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckFocusedElement(control); }); EnqueueTestComplete(); }
public void FocusPropertyNameWithDelay() { TestControl controlWithProperty_1 = new TestControl(); TestControl controlWithProperty_2 = new TestControl(); FocusBehavior behavior_1 = new FocusBehavior() { PropertyName = "TestProperty_1" }; FocusBehavior behavior_2 = new FocusBehavior() { PropertyName = "TestProperty_2" }; Interaction.GetBehaviors(controlWithProperty_1).Add(behavior_1); Interaction.GetBehaviors(controlWithProperty_2).Add(behavior_2); behavior_1.FocusDelay = TimeSpan.FromMilliseconds(400); behavior_2.FocusDelay = TimeSpan.FromMilliseconds(400); Grid grid = new Grid(); Button button = new Button(); grid.Children.Add(button); grid.Children.Add(controlWithProperty_1); grid.Children.Add(controlWithProperty_2); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(controlWithProperty_1); CheckUnfocusedElement(controlWithProperty_2); controlWithProperty_1.TestProperty_1 = "Hello"; CheckUnfocusedElement(controlWithProperty_1); }); EnqueueDelay(TimeSpan.FromMilliseconds(500)); EnqueueCallback(() => { CheckFocusedElement(controlWithProperty_1); controlWithProperty_2.TestProperty_2 = "Hello_"; CheckUnfocusedElement(controlWithProperty_2); }); EnqueueDelay(TimeSpan.FromMilliseconds(500)); EnqueueCallback(() => { CheckFocusedElement(controlWithProperty_2); }); EnqueueTestComplete(); }
public void GetFocusDelay() { FocusBehavior behavior = new FocusBehavior(); Action<double, double> checkFocusDelay = (double expectedInWpf, double expectedInSilverlight) => { Assert.AreEqual(TimeSpan.FromMilliseconds(expectedInWpf), behavior.GetFocusDelay()); }; Assert.AreEqual(null, behavior.FocusDelay); checkFocusDelay(0, 500); behavior.FocusDelay = TimeSpan.FromMilliseconds(800); checkFocusDelay(800, 800); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); behavior.EventName = "MouseEnter"; checkFocusDelay(0, 0); behavior.FocusDelay = TimeSpan.FromMilliseconds(800); checkFocusDelay(800, 800); }
public void GetFocusDelay() { FocusBehavior behavior = new FocusBehavior(); Action <double, double> checkFocusDelay = (double expectedInWpf, double expectedInSilverlight) => { Assert.AreEqual(TimeSpan.FromMilliseconds(expectedInWpf), behavior.GetFocusDelay()); }; Assert.AreEqual(null, behavior.FocusDelay); checkFocusDelay(0, 500); behavior.FocusDelay = TimeSpan.FromMilliseconds(800); checkFocusDelay(800, 800); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); behavior.EventName = "MouseEnter"; checkFocusDelay(0, 0); behavior.FocusDelay = TimeSpan.FromMilliseconds(800); checkFocusDelay(800, 800); }
public void FocusOnLoaded() { TextBox control = new TextBox(); FocusBehavior behavior = new FocusBehavior(); Interaction.GetBehaviors(control).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); grid.Children.Add(new Button()); grid.Children.Add(control); grid.Children.Add(new Button()); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckFocusedElement(control); }); EnqueueTestComplete(); }
public void FocusPropertyObjectChange() { TextBox control_1 = new TextBox() { IsReadOnly = false }; TextBox control_2 = new TextBox() { IsReadOnly = false }; TestControl controlWithProperty = new TestControl(); FocusBehavior behavior = new FocusBehavior() { PropertyName = "IsReadOnly", SourceObject = control_1 }; Interaction.GetBehaviors(controlWithProperty).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); Button button = new Button(); grid.Children.Add(button); grid.Children.Add(controlWithProperty); grid.Children.Add(control_1); grid.Children.Add(control_2); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(controlWithProperty); control_1.IsReadOnly = true; CheckFocusedElement(controlWithProperty); button.Focus(); behavior.SourceObject = control_2; CheckUnfocusedElement(controlWithProperty); control_2.IsReadOnly = true; CheckFocusedElement(controlWithProperty); }); EnqueueTestComplete(); }
public static async Task FocusAsync(this IJSRuntime jSRuntime, ElementReference target, FocusBehavior behavior, bool preventScroll = false) { try { await jSRuntime.InvokeVoidAsync(JSInteropConstants.Focus, target, preventScroll, behavior); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void FocusEventAndSourceName() { TextBox control = new TextBox(); TestControl controlWithEvent = new TestControl() { Name = "controlWithEvent" }; FocusBehavior behavior = new FocusBehavior() { EventName = "TestEvent", SourceName = "controlWithEvent" }; Interaction.GetBehaviors(control).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); grid.Children.Add(new Button()); grid.Children.Add(control); grid.Children.Add(new Button()); grid.Children.Add(controlWithEvent); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(control); controlWithEvent.RaiseTestEvent(); CheckFocusedElement(control); }); EnqueueTestComplete(); }
public void FocusPropertyNameWithDelay() { TestControl controlWithProperty_1 = new TestControl(); TestControl controlWithProperty_2 = new TestControl(); FocusBehavior behavior_1 = new FocusBehavior() { PropertyName = "TestProperty_1" }; FocusBehavior behavior_2 = new FocusBehavior() { PropertyName = "TestProperty_2" }; Interaction.GetBehaviors(controlWithProperty_1).Add(behavior_1); Interaction.GetBehaviors(controlWithProperty_2).Add(behavior_2); behavior_1.FocusDelay = TimeSpan.FromMilliseconds(400); behavior_2.FocusDelay = TimeSpan.FromMilliseconds(400); Grid grid = new Grid(); Button button = new Button(); grid.Children.Add(button); grid.Children.Add(controlWithProperty_1); grid.Children.Add(controlWithProperty_2); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(controlWithProperty_1); CheckUnfocusedElement(controlWithProperty_2); controlWithProperty_1.TestProperty_1 = "Hello"; CheckUnfocusedElement(controlWithProperty_1); }); EnqueueDelay(TimeSpan.FromMilliseconds(500)); EnqueueCallback(() => { CheckFocusedElement(controlWithProperty_1); controlWithProperty_2.TestProperty_2 = "Hello_"; CheckUnfocusedElement(controlWithProperty_2); }); EnqueueDelay(TimeSpan.FromMilliseconds(500)); EnqueueCallback(() => { CheckFocusedElement(controlWithProperty_2); }); EnqueueTestComplete(); }
public void FocusPropertyNameSourceName() { TextBox control = new TextBox(); TestControl controlWithProperty = new TestControl() { Name = "controlWithProperty" }; FocusBehavior behavior = new FocusBehavior() { PropertyName = "TestProperty_1", SourceName = "controlWithProperty" }; Interaction.GetBehaviors(control).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); Button button = new Button(); grid.Children.Add(button); grid.Children.Add(control); grid.Children.Add(controlWithProperty); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(control); controlWithProperty.TestProperty_1 = "Test"; CheckFocusedElement(control); }); EnqueueTestComplete(); }
public void PropertiesTest() { var behavior = new FocusBehavior(); TestsHelper.TestPublicPropertiesGetSet(behavior); }
/// <summary> /// Focus with behaviors. Behavior will work only for elements that are /// HTMLInputElement or HTMLTextAreaElement. Otherwise will only focus. /// </summary> /// <param name="target">Element that will receive focus.</param> /// <param name="behavior">Behavior of focused element</param> /// <param name="preventScroll">Whether to scroll to focused element</param> protected async Task FocusAsync(ElementReference target, FocusBehavior behavior, bool preventScroll = false) => await Js.FocusAsync(target, behavior, preventScroll);
public void FocusPropertyObjectChange() { TextBox control_1 = new TextBox() { IsReadOnly = false }; TextBox control_2 = new TextBox() { IsReadOnly = false }; TestControl controlWithProperty = new TestControl(); FocusBehavior behavior = new FocusBehavior() { PropertyName = "IsReadOnly", SourceObject = control_1 }; Interaction.GetBehaviors(controlWithProperty).Add(behavior); behavior.FocusDelay = TimeSpan.FromMilliseconds(0); Grid grid = new Grid(); Button button = new Button(); grid.Children.Add(button); grid.Children.Add(controlWithProperty); grid.Children.Add(control_1); grid.Children.Add(control_2); Window.Content = grid; EnqueueShowWindow(); EnqueueCallback(() => { CheckUnfocusedElement(controlWithProperty); control_1.IsReadOnly = true; CheckFocusedElement(controlWithProperty); button.Focus(); behavior.SourceObject = control_2; CheckUnfocusedElement(controlWithProperty); control_2.IsReadOnly = true; CheckFocusedElement(controlWithProperty); }); EnqueueTestComplete(); }