以编程方式命名 ScatterViewItem
目前,我正在 Microsoft Surface 上工作,主要创建一个基于数据库动态创建 ScatterViewItems 的应用程序(尽管没有绑定,但出于对问题不重要的原因。)当我尝试将名称注册到 SVI 时,我的问题就出现了将 ScatterView 放入控件之前。
声明 NameScope:
NameScope.SetNameScope(ActionArea, new NameScope());
创建/分配 SVI 名称
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);
}
稍后调用该名称 调用
ScatterViewItem to = (ScatterViewItem)ActionArea.FindName(name);
该名称时,FindName 返回 null。由此(并查看 SVI 的 Name 属性)我只能得出结论,我分配的名称是错误的。
那么如何为以编程方式创建的对象分配名称呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不用担心 NameScope - 很少需要。
Don't worry about NameScope - very very rarely needed.