WPF - 当“DisplayMemberPath”出现时,列出在 Blend 中不可见的项目被使用
我们目前正在研究如何实现 MVVM,我已经在 Blend 中设置了 MVVM Light Toolkit,并且可以指定在 Blend 中运行时提供的虚拟数据。一切都好。
我创建了一个虚拟数据列表。该列表包含名为 DummyItem 的非常简单的类的 6 个实例,该类具有 Age 和 Name 属性。
这是我的“DummyList”类的主要代码:
public class DummyItem{
public string Name;
public int Age;
public DummyItem(string name, int age){
this.Name = name;
this.Age = age;
}
}
public class DummyList : ArrayList
{
public DummyList()
{
this.Add(new DummyItem("Dummy1", 00));
this.Add(new DummyItem("Dummy2", 01));
this.Add(new DummyItem("Dummy3", 02));
this.Add(new DummyItem("Dummy4", 03));
this.Add(new DummyItem("Dummy5", 04));
this.Add(new DummyItem("Dummy6", 05));
}
}
这是我的 XAML 的操作部分。 DataContext 行确实有效并指向正确的 ViewModel。
<Grid x:Name="LayoutRoot">
<ListBox x:Name="ListViewBox"
DataContext="{Binding Source={StaticResource Locator}, Path=ListViewModel}"
ItemsSource="{Binding TheList}"
DisplayMemberPath="Name">
</ListBox>
</Grid>
问题是,当我添加“DisplayMemberPath”(如上面所示)时,我将无法再看到 Blend 中的列表项。如果我删除“DisplayMemberPath”,那么我会看到一个对象列表(DummyItem)及其完整路径。当应用程序运行时,一切都很完美。只是在 Blend 本身中,当我使用“DisplayMemberPath”时,我看不到列表项。
有人知道为什么当我使用 DisplayMemberPath 时看不到 Blend 本身内部的项目吗?
谢谢!
在
We're currently working out how to implement MVVM and I've got to the point where I've got the MVVM Light Toolkit set up in blend and can specify dummy data to be supplied if running in Blend. All good.
I've created a dummy list of data. The list contains 6 instances of a very simple class called DummyItem which has Age and Name properties.
Here's the main code from my 'DummyList' class:
public class DummyItem{
public string Name;
public int Age;
public DummyItem(string name, int age){
this.Name = name;
this.Age = age;
}
}
public class DummyList : ArrayList
{
public DummyList()
{
this.Add(new DummyItem("Dummy1", 00));
this.Add(new DummyItem("Dummy2", 01));
this.Add(new DummyItem("Dummy3", 02));
this.Add(new DummyItem("Dummy4", 03));
this.Add(new DummyItem("Dummy5", 04));
this.Add(new DummyItem("Dummy6", 05));
}
}
Here's the operative part of my XAML. The DataContext line does work and points to the correct ViewModel.
<Grid x:Name="LayoutRoot">
<ListBox x:Name="ListViewBox"
DataContext="{Binding Source={StaticResource Locator}, Path=ListViewModel}"
ItemsSource="{Binding TheList}"
DisplayMemberPath="Name">
</ListBox>
</Grid>
The problem is, when I add 'DisplayMemberPath', as I have above, then I can no longer see the list items in Blend. If I remove 'DisplayMemberPath', then I see a list of objects (DummyItem) with their full path. When the app is run, everything works perfectly. It's just that in Blend itself I cannot see the list items when I use 'DisplayMemberPath'.
Anyone know why I can't see the items inside Blend itself when I use DisplayMemberPath?
Thanks!
AT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试创建 Name 和 Age 属性:
Try making Name and Age properties: