User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

[Unity] Trouble adding framework elements dynamically

01 Jan 2015, 04:34

Hi,

I tried to add a ContentPresenter or a ContentControl dynamically at runtime. So I created a new ContentPresenter/Control, set the ContentTemplate and DataContext and added this newly created element to the root panel. Unfortunately I wasn't able to spot the newly added control even in an empty test project. So I tested certain other controls such as StackPanels, Buttons, etc. and only a few controls (StackPanel and TextBlock) appeared, while the TextBox and the Button don't appear.

The next things I tried was to give these controls a fixed size, set the alignment, set a background color, add a custom control template, etc. but nothing seems to work.

Has anyone a clue what I am doing wrong?


Oh, and Happy New Year everyone! :)
 
User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] Trouble adding framework elements dynamically

02 Jan 2015, 06:45

Okay, I figured it out. I just forgot to set the Content, instead I set the DataContext. (On a side note: In WPF I don't have to set the content in order for it to be displayed.)

But there still seems to be something odd when I do this in the OnPostInit() method of a UserControl that is added by XAML in the Main-XAML. Apparently the actual size doesn't get set, perhaps because the size of the root panel is still NAN and the ActualSize 0. So it is still not displayed as described in my first post. You can try it by just creating a button in code. But it works as mentioned with certain other controls.
 
User avatar
sfernandez
Site Admin
Posts: 3203
Joined: 22 Dec 2011, 19:20

Re: [Unity] Trouble adding framework elements dynamically

05 Jan 2015, 16:51

I answered the ticket you opened in our bugtracker about this issue.

Who is online

Users browsing this forum: No registered users and 5 guests