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 = (ScatterViewIte开发者_开发知识库m)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);
}
精彩评论