Identifying items in a User Control
Posted: 13 Oct 2013, 20:31
I have this user control:
I'm just trying to add items to the panel via code, but it keeps finding null as the value.
In the PostInit :
I've tried this, and it doesn't identify the panel. I tried assigning a name to the panel, and it couldn't identify it that way also (I used FindName<StackPanel>("MyPanelName")).
So...any recommendations on this? And along that note...should I even be assigning a name to something in a usercontrol, where the name might not be unique (I may have many stackpanels in that user control, and many instances of that control.)
Thanks,
JC
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" mc:Ignorable="d"
x:Class="UserControls.UC_AbilityBar" >
<StackPanel Orientation="Horizontal">
<Button>hey</Button>
</StackPanel>
</UserControl>In the PostInit :
Code: Select all
public void OnPostInit()
{
_PanelAbilities = GetContent().As<StackPanel>();
}I've tried this, and it doesn't identify the panel. I tried assigning a name to the panel, and it couldn't identify it that way also (I used FindName<StackPanel>("MyPanelName")).
So...any recommendations on this? And along that note...should I even be assigning a name to something in a usercontrol, where the name might not be unique (I may have many stackpanels in that user control, and many instances of that control.)
Thanks,
JC