1

I have a textbox which is binded to a property “display” of Viewmodel class

My current logic:
I have a keyboard whenever key is pressed the key is appending at the end of existing string text box.

What I want: when key is pressed, based on the cursor position my key should be appended(not at the end) EX: “Stack” is a string. My current cursor position is after “S”, if I press the key “G”, property “display” of Viewmodel class should have “SGtack” (textbox shows “SGtack” but “Display” is still StackG)

user2890924
  • 11
  • 1
  • 4

1 Answers1

0

in your ViewModel you must have :

display Property to keep the text of textbox

CurrentPosition to bind the SelectionStart of textbox

and newChar which is the new character you wanna add to the textbox

when you click a button you should have something like this

    String newDisplay = display.substring(0,CurrentPosition) + newChar +
 display.substring(CurrentPosition,display.lenght - CurrentPosition);
mohammad jannesary
  • 1,811
  • 1
  • 26
  • 27