4

I work with a custom TextBox in a winform project, I added this property in my custom TextBox:

private TextBox _nextControl;

public TextBox NextControl 
{
    set { _nextControl=value; }
    get { return _nextControl; }
}

and I got this result for a form with 2 TextBox(textBox1 and textBox2) in my custom TextBox properties with the property NextControl; I can see all TextBoxes in the form:

enter image description here

In this case the property NextControl will show all TextBox in my form to select my next control.

But when I want to do the same in my new WPF costum TextBox I got this with the same condition(2 TextBoxes, textBox1 and textBox2):

enter image description here

Why I don't have the same result? And how to do this in my WPF project?


Update:

For more explanation, in my winform project I use the property NextControl to select the next control from the UI properties.

protected override void OnKeyDown(KeyEventArgs e) 
{
    if(e.KeyCode==Keys.Down) 
        // select the next TextBox chosen in this TextBox option
        _nextControl.Select(); 
}

Because I can already choose the name of the next TextBox in UI, I don't want to do this with extra code.

But this not work in WPF: I can't see the names of my TextBoxes in my window for the property NextControl(automatically in winform if I choose the type of property = TextBox).

p.s.: My custom TextBox inherited from System.Windows.Controls.TextBox.


Update:

I uploded a winform project with the custom TextBox [here] of a sample project for what I want a WPF can behaves the same.

I've updated the link of this sample.

Ken Kin
  • 4,503
  • 3
  • 38
  • 76
Akrem
  • 5,033
  • 8
  • 37
  • 64
  • I don't really know what you are doing. Please describe more clearly what you are doing, whats not working and what you have tried. If possible, provide a small example of the problem. But remember if you bind a TextBox to the content of a combobox, you will only get the name of the class. Which is the default behavior in wpf, everytime it encounters something that he can't display directly. Because you haven't supplied a template. – dowhilefor May 02 '13 at 13:41
  • It's similar to http://stackoverflow.com/questions/8203329/moving-to-next-control-on-enter-keypress-in-wpf – misak May 03 '13 at 09:20
  • @misak I want to use that in costum textBox and I want to show all text Box control on my form in textBox property – Akrem May 03 '13 at 09:25
  • Can you upload your sample code somewhere so I can give it a try? – Jegan May 09 '13 at 09:22
  • @Jegan I added a project sample – Akrem May 09 '13 at 10:05
  • I was hoping that you will upload the files somewhere open source repository such as github, so I can download the files quickly and have a look. but the location you uploaded the files "4Shared" will not let me download the files without me registering with them, which I am not intend to do. – Jegan May 09 '13 at 11:22
  • @Jegan : I update the linq to download this sample, it's better to see this than the code (the property in UI – Akrem May 09 '13 at 11:39

3 Answers3

1

Quick look in your code is telling me that your Windows Form User Control is not compatible with WPF, specially the keyDown event in Windows Form parses parameter "KeyEventArgs e", this is a System.Windows.Form.Key but WPF parses "System.Windows.Input.Key" and WPF doesn't have "Select() method for textbox. Also the WPF binds controls in very different way to the WinForm, therefore your WinFromuserControl Will not work in WPF forms.

If you want to use similar behavior in your WPF form, you have to write one that will be supported in WPF.

Jegan
  • 1,227
  • 9
  • 16
  • I know that, I just want to know how to change the property NextControl in my WPF project to get the same result – Akrem May 09 '13 at 17:11
1

From your explanation what I could understand is,

  • You are using a custom text box class which have NextControl property of Type TextBox
  • You need the Custom text box to automatically transfer focus to the next text box when you press the down arrow key
  • You need Visual Studio design support to select which is the next control for all your CustomTextBox instances.
  • Earlier in Winforms Visual studio supported selection of available matched types from the interface. But now in WPF its not supporting out of the box. (We can achieve this by extending the property grid)
  • In your case you can make the NextControl as dependency property and achieve the relation to the next control using data binding
  • For data binding you need to click on the square displayed in property grid at the end of property name but left of property drop down.

Hope you are aware of dependency properties and WPF data binding. The binding you need to use is the the Element name binding.

Joy George Kunjikkuru
  • 1,495
  • 13
  • 27
1

Based on the fact you are looking for a textbox (a known value) the WinForms application is helping you out filling the propertygrid. Like is true for most of your own controls in WinForms you need to suply the values yourself in WPF this time.

The how part of your question has in basis been answered here and here

Implementing the ICustomTypeDescriptor seems like a hard thing to do but actually most functions can just return the TypeDescriptor's implementation.

The only interesting one is GetProperties where you can return a new PropertyDescriptorCollection that contains the array returned from control.Children.OfType();

Community
  • 1
  • 1