Ticket T236952
Visible to All Users

WPF TextEdit EditValue does not hold it's value when set in code behind

created 10 years ago

Hi,

Can you please tell me the conditions under which the EditValue of a WPF TextEdit can be updated? Does the control need to have focus in order for the two way binding to work?

I have a grid control that is bound to a viewmodel that is populated using the entityframework.

As there are issues using the touch keyboard in WPF on a Surface Pro tablet, I am trying to use the Virtual Keyboard provided by James Hurst (https://jhvirtualkeyboard.codeplex.com/). This involves setting the EditValue of the TextEdit (actually a derived class of this) that is created internally for the GridColumn.

Whenever I set EditValue, the text is visible in the control on the screen. But when I click on another row and then back onto the edited column cell, the value returns to the original value.

I think this maybe due to the fact that the Virtual Keyboard takes over focus when typing? When the cell is clicked/touched, the virtual keyboard is opened and it's current target is set to the cell in question. Once you start typing on the keyboard, the focus transfers away from the cell and onto the keyboard. The keyboard then calls an implemented interface method on the TextEdit derived class which is where I'm updating the EditValue. The Dependency Property set method does not get called and hence the Raise Property Changed method does not update the entity object.

If I don't show the virtual keyboard and just use the physical keyboard on a PC then the updates are persisted as expected. I guess this is because the control has focus and it's updated using the internal mechanism on focus lost. I did notice that the Dependency Property set method is called this way and hence the Raise Property Changed method is called. Obviously my setting of EditValue is bypassed using the physical keyboard method.

Sorry but I can't post my code. I can try and knock an example up if you really need it. I've not tried this on the tablet yet as I can't get it to work yet, so I'm trying this on a Win 7 machine.

Thanks,

John

Show previous comments (5)
Andrey Marten (DevExpress Support) 10 years ago

    Hello John,

    Due to bad performance when Automation UI is used with WPF controls, the corresponding events are not used by default if you use GridControl (Bad performance because of Automation events). That is why if you add it into the window, the touch keyboard does not appear even on touch in DataGrid's cells. To disable this behavior, set the static ClearAutomationEventsHelper.IsEnabled property to False.

    Wpf controls do not support opening the touch keyboard automatically by default, and the approach suggested in the article (Automatic Touch Keyboard for TextBoxes in WPF Applications on Windows 8+) is a kind of a workaround that works correctly for standard WPF controls. This approach will not work with our GridControl out of the box, and I do not see an easy way to achieve the desired functionality.

    As you mentioned above, the only issue is that the value returned in the GridCellAutomationPeer.IsKeyboardFocusable method is always False. I've created GridCellAutomationPeer and overridden the IsKeyboardFocusableCore method to make it return always True, but the workaround from that article still does not work in GridControl. See the attached sample. Perhaps, there are additional requirements that should be implemented in the AutomationPeer.

    Thanks,
    Andrey

    JW JW
    John Williams 10 10 years ago

      Hi Andrey,
      Thanks for the information and the example project. I've found this other link that says for a control to be able to invoke the on-screen touch keyboard when it obtains input focus, it must have a custom automation peer that derives from FrameworkElementAutomationPeer and implements the IValueProvider and ITextProvider interfaces.
      https://books.google.co.uk/books?id=Da9CAwAAQBAJ&pg=PA890&lpg=PA890&dq=ITextProvider+touch+keyboard&source=bl&ots=cNTkn2czkG&sig=PKNAIhdwATWgbsU5ZqhWaC0VZEY&hl=en&sa=X&ei=I_xSVb-RK8Ou7Abns4HgDg&ved=0CEYQ6AEwBg#v=onepage&q=ITextProvider%20touch%20keyboard&f=false
      I see that GridCellAutomationPeer does not derive from FrameworkElementAutomationPeer and I'm unsure how I can adapt it to test if it gives us what we want. Anyway, I thought I'd provide this link to you in case that here is something that your developers can do for future versions.
      I think we've exhausted all possiilities on this, so will probably launch the tabtip.exe process in order to show the keyboard.
      I'll let you know on my work account if we manage to come up with a better solution.
      Thanks very much for you help.
      John

      Andrey Marten (DevExpress Support) 10 years ago

        Hello John,

        Thank you for additional information. Since WPF controls do not support such a functionality out of the box, we cannot provide you with a working approach for GridControl. Even if the workaround suggested in the first link works for GridControl, its usage is not a good way, since it has some side effects like switching off scrolling in the grid.

        Our developers will research this question in the future, and perhaps we will find a way to automatically open the on-screen touch keyboard when a cell editor is opened. Stay tuned to our announcements.

        Please do not hesitate to contact us if you have any further difficulties with this. We are always happy to assist you, John!

        Thanks,
        Andrey

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.