View Issue Details

IDProjectCategoryView StatusLast Update
0002521NoesisGUIC# SDKpublic2023-03-01 10:38
Reportervoula_d Assigned Tosfernandez  
Status resolvedResolutionno change required 
Product Version3.1.7 
Summary0002521: Adding controls to canvas dynamically not working
DescriptionI'm trying to add controls to a canvas by dynamically loading xaml. But no controls are added to the canvas, or rather I can see that they are added as Children but never get rendered. I get the following error in the output: Null item added to UIElementCollection. The following link contains code that reproduces the issue.
TagsNo tags attached.




2023-02-23 19:40

manager   ~0008303

The error message indicates that you are trying to add a null object to the UIElement collection.
Debugging a bit your application I realized that you are redefining the UserControl type to point to NoesisUserControl:
using UserControl = Noesis.Portability.NoesisUserControl;

And the xaml you are dynamically loading is a plain UserControl, but when adding it to the Canvas you are casting to NoesisUserControl (because of the type redefinition), so the cast returns null. Changing the cast to UIElement for example will fix it:
theCanvas.Children.Add(child as UIElement);


2023-02-24 09:37

reporter   ~0008305

You are absolutely right and I am sorry for the silly mistake. The sample now works but our production scenario is a lot more complex and it still does not work as expected, i.e. controls are not added to the canvas dynamically. I will try to reproduce our problem again and will get back to you. Thank you.


2023-03-01 10:38

manager   ~0008317

Marking this as solved. If necessary, please, open a new ticket with a more specific problem.

Issue History

Date Modified Username Field Change
2023-02-23 17:06 voula_d New Issue
2023-02-23 19:31 sfernandez Assigned To => sfernandez
2023-02-23 19:31 sfernandez Status new => assigned
2023-02-23 19:40 sfernandez Status assigned => feedback
2023-02-23 19:40 sfernandez Note Added: 0008303
2023-02-24 09:37 voula_d Note Added: 0008305
2023-02-24 09:37 voula_d Status feedback => assigned
2023-03-01 10:38 jsantos Status assigned => resolved
2023-03-01 10:38 jsantos Resolution open => no change required
2023-03-01 10:38 jsantos Note Added: 0008317