All,
I have a generic list defined in a user control.
private List<string> m_AnimationNames = new List<string>();
public List<string> AnimationNames
{
get { return this.m_AnimationNames; }
set { this.m_AnimationNames = value; }
}
I refer to this list in xaml and populate it like this.
<local:AnimatedCharacter.AnimationNames>
<System:String>Walk</System:String>
<System:String>Run</System:String>
<System:String>Talk</System:String>
</local:AnimatedCharacter.AnimationNames>
Then I try to reference this list elsewhere in the code, after calling InitializeComponent (), and the list always returns size 0 and contains no elements.
Why is this list empty at runtime? What am I missing, what does this list count 0 do when I access it in code?
Full class:
public partial class AnimatedCharacter : UserControl
{
private List<string> m_AnimationNames = new List<string>();
public AnimatedCharacter()
{
InitializeComponent();
DoSomething();
}
public List<string> AnimationNames
{
get { return this.m_AnimationNames; }
set { this.m_AnimationNames = value; }
}
public void DoSomething(){
Console.WriteLine("Anim: " + AnimationNames.Count);
}
}
}
XAML example:
<local:AnimatedCharacter x:Name="ac_guy1" Height="315" Width="273" Canvas.Left="-666" Canvas.Top="-99" >
<local:AnimatedCharacter.AnimationNames>
<System:String>Walk</System:String>
<System:String>Run</System:String>
<System:String>Talk</System:String>
</local:AnimatedCharacter.AnimationNames>
</local:AnimatedCharacter>
source
share