Jag försöker att köra FindName och det funkar fint på alla kontroller som jag själv lagt dit i VS.Net men inte dom som läggs dit via kod. Funkar inte FindName i runtime och i så fall hur skapar man en referens till dom? Hm..? Windows Forms? Har du satt name-egenskapen till någonting? Det är WPF Windows Forms. Jo då alla får ett eget namn via en loop. Dom heter Img plus ett nummer. WPF != "Windows Forms" har du lagt till de runtime skapade kontrollerna till formulärets controlsCollection? tack,RegisterName funkade fint fint.Tack för hjälpenköra FindName på dynamisk skapad kontroll
felet jag får är ju:
<code>
Object not set to an instans of the object
</code>Sv: köra FindName på dynamisk skapad kontroll
Sv:köra FindName på dynamisk skapad kontroll
Sv: köra FindName på dynamisk skapad kontroll
Men är det WPF det är frågan om, måste du tydligen kalla på RegisterName.
MSDN (FrameworkElement.FindName):
FindName operates within the current element's namescope. For details, see WPF Namescopes.
MSDN (WPF Namescopes):
Adding Elements to Parsed Element Trees
Any additions to the element tree after loading and processing must call the appropriate implementation of RegisterName for the class that defines the namescope. Otherwise, the added object cannot be referenced by name through methods such as FindName. <b>Merely setting a Name property (or x:Name Attribute) does not register that name into any namescope.</b> Adding a named element to an element tree that has a namescope also does not register the name to the namescope. Although namescopes can be nested, you generally register names to the namescope that exists on the root element, so that your namescope location parallels the namescope that would have been created in an equivalent loaded XAML page. The most common scenario for application developers is that you will use RegisterName to register names into the namescope on the current root. RegisterName is part of one important scenario for finding storyboards that will run as animations. For more information, see Storyboards Overview. If you call RegisterName on an element other than the root element in the same logical tree, the name is still registered to the rootmost element, as if you had called RegisterName on the root element.Sv: köra FindName på dynamisk skapad kontroll
Sv:köra FindName på dynamisk skapad kontroll