开发者

Name a ScatterViewItem programmatically

开发者 https://www.devze.com 2023-02-17 14:07 出处:网络
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

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 = (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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消