question

IDGO-6443 avatar image
IDGO-6443 asked ·

UWP : Need Close Button in CustomEditControl and Mouse Events to be Active..

I have attached the project below..

  1. Need Close Button in the textbox

  2. Need Mouse Events or cursor postion to be active in the textbox.


https://1drv.ms/u/s!Ag8QU6ar3yRugYg7U-qDJ1o4VraieQ?e=8OnEqi

s!Ag8QU6ar3yRugYg7U-qDJ1o4VraieQ


4842-sdfsdf.gif


windows-uwpwindows-wpfwindows-uwp-xaml
sdfsdf.gif (115.2 KiB)
7 comments
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

4851-sdfsdfsdfsdfsdfsdfsdfsdfsd.png




With the above code... I was able to add close button, But none of the Mouse Events are Working...



0 Votes 0 · ·
   void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
         {
          / See whether the pointer is inside or outside the control.
             Rect contentRect = GetElementRect(BorderPanel);
             if (contentRect.Contains(args.CurrentPoint.Position))
             {
                 UpdateTargetBoxID?.Invoke(uniqueKey, Type);
                 if (IsReadOnly || !IsEnabled) return;
                 SetInternalFocus(uniqueKey);
                 Focus(FocusState.Programmatic);  //Todo: A more complete custom control would move the caret to the pointer position. It would also provide some way to select
             }
             else
             {
         }


If I put breakPoint in the above code....Deletebutton Event Will Fire...Else it wont Fire.





0 Votes 0 · ·

Hello, The TextBox provided by UWP is a control for processing text input, and it contains a delete button. Do you have any special requirements for this input control?

0 Votes 0 · ·
IDGO-6443 avatar image IDGO-6443 RichardZhang-MSFT ·

**Yes Richard....I need this CustomEditControl itself because we are few Issue in Uwp Textbox, i.e On Screen Keyboard and few other Issues.

Almost everything is working in CustomEditControl Now....I need Only Mouse Events to be Working in customEditControl...I have attached the project above..**

  1. Close Mark Mouse Event

  2. Text Cursor moment in Mouse (Keyboard Arror keys are Working but using Mouse its not working)


0 Votes 0 · ·

Hi, In contrast, you can modify your project first and add DeleteButton to the existing project (the project I downloaded does not include DeleteButton). In addition, it is recommended that you write down the problems encountered in the use of TextBox in detail, there may be other solutions.

0 Votes 0 · ·
Show more comments

1 Answer

RichardZhang-MSFT avatar image
RichardZhang-MSFT answered ·

Hello,​

Welcome to our Microsoft Q&A platform!

I checked your project and the problem appeared on the CoreWindow_PointerPressed method.

When you click the delete button, the button is not actually clicked. CoreWindow_PointerPressed is like a layer of paper in the middle, blocking your pointer pressed operation.

It is not recommended to listen to the pointer pressed event of the entire Window for a control.

The purpose of your CoreWindow_PointerPressed method is to determine whether the control should get focus when the pointer pressed, and change the state of the control. In fact, this does not need to listen to the PointerPressed event, it only needs to listen to the CustomEditControl.GotFocus and CustomEditControl.LostFocus events.

So the suggestions for your problems are as follows:

  1. Cancel all event monitoring on CoreWindow to avoid mutual interference between events.

  2. Handle the state of the control through Focus related events.

As for getting the cursor to the specified position by pointer pressed, this point needs to be analyzed according to the pointer pressed coordinates, and the StartCaretPosition should be changed.



Nevertheless, I still recommend using the default TextBox. The native controls have been tested many times and have integrated many functions. Modifying based on the native TextBox control is easier than writing a TextBox control yourself.

Thanks.

14 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


 1.  CustomTextControl Clear Button is Working Now on PointerPressed Event.. I have attached project and below is the code.

I need only Mouse Cursor and Select Text in CustomTextControl ...

     TextBox is not fulfilling my requirement, thats the reason I have been working on this, I need Only 1 thing i.e  **I need only Mouse Cursor and Select Text in  CustomTextControl** ..

  I am also extensively working on this.. https://1drv.ms/u/s!Ag8QU6ar3yRugYhixSYMqhYeKox1Xg?e=Cx0MAk

s!Ag8QU6ar3yRugYhixSYMqhYeKox1Xg




0 Votes 0 · ·
         void CoreWindow_PointerPressed(CoreWindow sender, PointerEventArgs args)
         {
             Rect contentRect = GetElementRect(BorderPanel);
             if (contentRect.Contains(args.CurrentPoint.Position))
             {
                 var mm = GetElementRect(ClearButton);
                 if (mm.Contains(args.CurrentPoint.Position))
                 {
                     Text = string.Empty;
                     var range = Selection;
                     SetSelectionAndNotify(range);
                     args.Handled = true;
                     return;
                 }

I need Only 1 thing i.e I need only Mouse Cursor and Select Text in CustomTextControl Using Mouse..


0 Votes 0 · ·

@ RichardZhang-MSFT

After Extensively working on textblock selection. I Just need last piece of the puzzle to close post. : Need Selection Color

Selection Text is working but Selection Color is not changing.

5221-need-selection-color.gif


Have attached the project , Just Need Selection Color
s!Ag8QU6ar3yRugYhmJMEEBRyP5ag74A



https://1drv.ms/u/s!Ag8QU6ar3yRugYhmJMEEBRyP5ag74A?e=OYGd0w

0 Votes 0 · ·

Hi, If you want to enable text selection (including the selected background color), you can set TextBlock's IsTextSelectionEnabled = True

0 Votes 0 · ·
IDGO-6443 avatar image IDGO-6443 RichardZhang-MSFT ·

I tried IsTextSelectionEnabled = True in the beginning of my project and Now as well (Its not working)...You can also download the above link and cross check.

0 Votes 0 · ·
Show more comments