Currently I'm working on the Microsoft Surface primarily creating an application that dynamically creates ScatterViewItems based on a database (Though not binded, for reasons that are unimportant to the question.) My problem comes when I try to register a Name to an SVI with a ScatterView before placing it in the control.
Declaring the NameScope:
NameScope.SetNameScope(ActionArea, new NameScope());
Creating/Assigning the SVI a name
foreach(KeyValuePair<int,Node> i in nodes)
{
ScatterViewItem item = new ScatterViewItem();
item.Content = i.Value.Argument;
item.Tag = i.Value;
ActionArea.RegisterName("NodeID" + i.Key.ToString(), item);
ActionArea.Items.Add(item);
}
Calling the name later on
ScatterViewItem to = (ScatterViewItem)ActionArea.FindName(name);
When this is called, FindName returns null. From this (and looking at the SVI's Name property) I can only conclude I'm assigning the name wrong.
So how do you assign a name to a programmatically created object?
Don't worry about NameScope - very very rarely needed.
foreach(KeyValuePair<int,Node> i in nodes)
{
ScatterViewItem item = new ScatterViewItem();
item.Content = i.Value.Argument;
item.Tag = i.Value;
item.Name = "NodeID" + i.Key.ToString(); // set the name property
ActionArea.Items.Add(item);
}