-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58e477b
commit 02e3c5d
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/SamplesApp/UITests.Shared/Windows_UI_Input/PointersTests/TextBox_Pointer.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Page x:Class="UITests.Shared.Windows_UI_Input.PointersTests.TextBoxPointer" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Shared.Windows_UI_Input.PointersTests" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<StackPanel> | ||
<StackPanel Orientation="Horizontal" | ||
Margin="0,20"> | ||
<Border x:Name="TestTextBoxBorder" | ||
Background="LightGray" | ||
Width="300" | ||
Height="50"> | ||
<TextBox x:Name="TestTextBox" | ||
Text="Default Text" | ||
VerticalAlignment="Center" | ||
HorizontalAlignment="Center" /> | ||
</Border> | ||
|
||
<TextBlock x:Name="ResultText" | ||
Text="No action yet" | ||
Margin="10,0,0,0" /> | ||
</StackPanel> | ||
</StackPanel> | ||
</Page> |
67 changes: 67 additions & 0 deletions
67
src/SamplesApp/UITests.Shared/Windows_UI_Input/PointersTests/TextBox_Pointer.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Input; | ||
using Uno.UI.Samples.Controls; | ||
using Windows.Foundation; | ||
|
||
namespace UITests.Shared.Windows_UI_Input.PointersTests | ||
{ | ||
[Sample("Pointers",Description = "This sample tests an issue where dragging on a TextBox selects text incorrectly. To ensures that dragging across the TextBox does not select text unless explicitly selected.")] | ||
public sealed partial class TextBoxPointer : Page | ||
{ | ||
public TextBoxPointer() | ||
{ | ||
this.InitializeComponent(); | ||
SetupPointerEvents(); | ||
} | ||
|
||
private void SetupPointerEvents() | ||
{ | ||
TestTextBoxBorder.PointerPressed += OnPointerPressed; | ||
TestTextBoxBorder.PointerMoved += OnPointerMoved; | ||
TestTextBoxBorder.PointerReleased += OnPointerReleased; | ||
} | ||
|
||
private bool _isDragging; | ||
private Point? _initialPoint; | ||
|
||
private void OnPointerPressed(object sender, PointerRoutedEventArgs e) | ||
{ | ||
_initialPoint = e.GetCurrentPoint(TestTextBoxBorder).Position; | ||
_isDragging = false; | ||
ResultText.Text = "Pointer Pressed"; | ||
} | ||
|
||
private void OnPointerMoved(object sender, PointerRoutedEventArgs e) | ||
{ | ||
if (_initialPoint is Point initialPoint) | ||
{ | ||
var currentPoint = e.GetCurrentPoint(TestTextBoxBorder).Position; | ||
|
||
if (Math.Abs(currentPoint.X - initialPoint.X) > 2 || Math.Abs(currentPoint.Y - initialPoint.Y) > 2) | ||
{ | ||
_isDragging = true; | ||
ResultText.Text = "Pointer Dragging"; | ||
} | ||
} | ||
} | ||
|
||
private void OnPointerReleased(object sender, PointerRoutedEventArgs e) | ||
{ | ||
if (_isDragging) | ||
{ | ||
var selectedText = TestTextBox.SelectedText; | ||
ResultText.Text = string.IsNullOrEmpty(selectedText) | ||
? "Pointer Released - No text selected" | ||
: $"Pointer Released - Selected Text: '{selectedText}'"; | ||
} | ||
else | ||
{ | ||
ResultText.Text = "Pointer Released - No drag detected"; | ||
} | ||
|
||
_isDragging = false; | ||
_initialPoint = null; | ||
} | ||
} | ||
} |