Element added to DockPanel at runtime not shown
Posted: 24 Oct 2013, 14:36
Hey,
I am using the following code to add a TextBlock at runtime to an existing DockPanel (which came from a xaml file):
But the added text is not there. Nothing is added to the panel,it seems.
I can hide/manipulate existing elements inside the panel at runtime without a problem, but this TextBlock is never visible. It doesn't crash, so I suppose it is there somehow, but not being rendered.
Here is the original DockPanel xaml:
Maybe I'm doing something simple somehow very wrong 
I am using the following code to add a TextBlock at runtime to an existing DockPanel (which came from a xaml file):
Code: Select all
// Insert our fps text field
_fpsText = new Noesis::Gui::TextBlock();
_fpsText->SetText("FPS: 0");
_fpsText->SetFontSize(20.0f);
_fpsText->SetTextAlignment(Noesis::Gui::TextAlignment_Center);
_fpsText->SetForeground((Noesis::Gui::Brush*)Noesis::Gui::Brushes::White());
// Ugly workaround, but the DockPanel does not have a name
// TODO: fix when on Windows
Noesis::Gui::TextBlock* status = (Noesis::Gui::TextBlock*)_xamlRoot->FindName("txtStatus");
((Noesis::Gui::DockPanel*)status->GetParent())->GetChildren()->Add(_fpsText);
Noesis::Gui::DockPanel::SetDock(_fpsText, Noesis::Gui::Dock_Bottom);I can hide/manipulate existing elements inside the panel at runtime without a problem, but this TextBlock is never visible. It doesn't crash, so I suppose it is there somehow, but not being rendered.
Here is the original DockPanel xaml:
Code: Select all
<DockPanel>
<TextBlock x:Name="txtStatus"
DockPanel.Dock="Bottom" Margin="0,0,0,10" FontSize="20" Foreground="White" Text="I am OK!" TextAlignment="Center"/>
<TextBlock
DockPanel.Dock="Top" Margin="0,0,0,10" FontSize="24" Foreground="White" Text="The Player" TextAlignment="Center"/>
<Image x:Name="imgNorm"
DockPanel.Dock="Top" Source="images/jan_ok.png" Stretch="Uniform"/>
<Image x:Name="imgJump"
DockPanel.Dock="Top" Visibility="Collapsed" Source="images/jan_jump.png" Stretch="Uniform"/>
</DockPanel>