Wpf Textbox in property manager page

I have a WFP userControl with a text box implemented into property manager page but in that text box I can delete, backspace, spacebar, but I can NOT type in new words, letters or numbers. I CAN paste from notepad though. Upon my research I realised that it is a common scenario when you use ElemenHost in winform to host WPF. However I don’t know how I can fix this problem inside the property manager page please see below.

[.net 3.5 - Why is my WPF textbox "kinda" readonly? - Stack Overflow](stack over flow question with the same problem)

[ElementHost.EnableModelessKeyboardInterop(Window) Method (System.Windows.Forms.Integration) | Microsoft Docs](microsoft docs)

Yes, this is a known issue (it not only affects PMPages, but also Task Panes, Feature Manager tabs etc.). Try this example which is based on xCAD.NET (which has this properly fixed within the framework). You can explore how it is done here as xCAD is open-source or you can just use xCAD ( you might have noticed that the sample I attached is hardly 100 lines and it is probably 10-20 times less for the equivalent you do with vanilla SOLIDWORKS API)

2 Likes

Solidworks API support team gave me this answer. basically you listen to all the alphanumerical key strokes in the WPF controller and update the textbox manually.
the good thing about this is that it has nothing to do with Solidworks objects in property manager page and doesn’t require specific packages.

private void AbhaysTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            Key curKey = e.Key;
            string sCurKey = "";
            char curChar = (char)0;
            int iChar = 0;
            if (curKey >= Key.D0 && curKey <= Key.D9)
            {
                curChar = (char)14;
            }
            else if ((curKey >= Key.NumPad0) && (curKey <= Key.NumPad9))
            {
                iChar = -26;
            }
            else if(curKey >= Key.A && curKey <= Key.Z)
            {
                bool isCapslock = Keyboard.IsKeyToggled(Key.CapsLock);
                bool isShift = (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift));
                if ((isCapslock && isShift) || (!isCapslock && !isShift))
                {
                    curChar = (char)53;
                }
                else
                {
                    curChar = (char)21;
                }
            }

            if(iChar != 0)
            {
                iChar += (int)curKey;
                curChar = (char)iChar;
            }
            else if(curChar != 0)
            {
                curChar += (char)curKey;
            }

            if(curChar != 0)
            {
                sCurKey = curChar.ToString();
                string sText = AbhaysTextBox.Text;
                int iSelStart = AbhaysTextBox.SelectionStart;
                sText = sText.Insert(iSelStart, sCurKey);
                AbhaysTextBox.Text = sText;
                AbhaysTextBox.SelectionStart = iSelStart + 1;
            }
        }