简体   繁体   中英

Hide Touch Selection grippers from UWP RichEditBox

I have created a UWP app which used RichEditBox to display contents of a file having multiple lines. Based on the selection changed events from the control, line is selected and further actions are performed in the user interface.

However, when I tap the same line again, the grippers appear. I would want to complete avoid showing the grippers as this allows moving the selection over a range of lines which does not serve any purpose in the app.

The gripper appears on touch devices. I want the gripper to be hidden, and would like to know if there is a programmatic way to do this.

Touch Selection Gripper

Update

If I understand you correctly, you want to prevent the selection text change from user's action. A possbile workaround for your requirement is that you could handle the RichEditBox.SelectionChanging Event when user wants to move and select other text. In the SelectionChanging, you could manually set the selection text of the RichEditBox to the original text. The behavior looks like the drag text function is disabled.

Here is the code that I used for test.

Xaml Part:

 <RichEditBox x:Name="MyRichEditBox" Width="800" Height="300" SelectionChanging="RichEditBox_SelectionChanging" />

Code-behind

 public MainPage()
    {
        this.InitializeComponent();
        //for test purpose, i manually set the selectioned text at the begining
        MyRichEditBox.Document.SetText(Windows.UI.Text.TextSetOptions.None, "This is some sample text");
        var selectedText = MyRichEditBox.Document.Selection;
        selectedText.SetRange(3, 15);
    }
    private void RichEditBox_SelectionChanging(RichEditBox sender, RichEditBoxSelectionChangingEventArgs args)
    {
        //when selection starts to change, keep the selection back to original one
        var selectedText = MyRichEditBox.Document.Selection;
        selectedText.SetRange(3, 15);
    }

Old replay:

I have to say that showing the gripper is the default behavior of TextBox in UWP. We can't modify it now.

Besides, I noticed that the gripper should appears when running on touchable devices like a surface. When running the app on my PC, there is no gripper when I select the text in the RichEditBox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM