Search for dynamically generated Wcf controls using FindName ()

The FramworkElement.FindName () method to search for a control in the parent control looks as if it should go straight ahead ...

But I raise a question, and it seems to me that the frame does not like what I'm trying to do.

Firstly, I understand that there are many different ways to do things and keep in mind that this is the first form I create in WPF.

I load controls into a StackPanel based on the number of items in the collection. This method is required because the collection is determined by the number of directories inside the [user-entered URL].

The list builds horizontal stack panels into a vertical glass panel that fits into the mold during development.

So dirStackPanel is in form. I insert controlStackPanel into dirStackPanel n number of times and name each with an identification name: (string) ("controlStackPanel" + n).

I also populate the controlStackPanel with controls, but this is a moot point, given that I cannot get the controlstackPanel from my parent (dirStackPanel) by name.

Example:

var getPanel = (StackPanel) this.dirStackPanel.FindName((string)("controlStackPanel" + n)) Returns null

So, for each control that I insert at WORK TIME, a name is assigned and it can be easily obtained using a loop. But the FindName method will not work on the first child of the parent "StackPanel" control. It continues to return zero, not an object.

Any ideas?

+3
source share
1 answer

, RegisterName, .

:

dirStackPanel.RegisterName(controlStackPanel.Name, controlStackPanel);
+8

All Articles