msdn 数据模板概述
我正在关注 msdn 数据模板概述 http://msdn.microsoft.com/en -us/library/ms742521.aspx
但我觉得他们错过了一些解释..对于他们拥有的资源:
<Window.Resources><local:Tasks x:Key="myTodoList"/></Window.Resources>
他们在 XAML 中拥有的
<ListBox Width="400" Margin="10"
ItemsSource="{Binding Source={StaticResource myTodoList}}"/>
只是在不显示背后的 C# 代码的情况下,他们能够在列表框。 ListBox 没有 x:Name,我无法在 MainWindow 中添加项目,并且使用单独的类任务,我执行了以下操作(这不起作用)
using System.Collections; // use ArrayList
using System.Collections.ObjectModel; // use Observable Collection
namespace FooApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class Tasks : ObservableCollection<Tasks>
{
string TaskName;
string Description;
int Priority;
public TasksStuff(string taskName, string description, int priority)
{
this.taskName = TaskName;
this.description = Description;
this.priority = Priority;
}
public string TaskName
{get{return this.taskName}}
public string Description
{get{return this.description}}
public string Priority
{get{return this.priority}}
private ArrayList Tasks
{
ArrayList taskList = new ArrayList();
taskList.Add( new TasksStuff("A foo task", "doing foo",1));
return taskList;
}
}
}
我真的很困惑。
I'm following msdn data templating overview http://msdn.microsoft.com/en-us/library/ms742521.aspx
But I felt they missed explaining something..for resources they have:
<Window.Resources><local:Tasks x:Key="myTodoList"/></Window.Resources>
And all they have in XAML is
<ListBox Width="400" Margin="10"
ItemsSource="{Binding Source={StaticResource myTodoList}}"/>
Without showing how C# code behind, they were able to show a list of items in the ListBox. The ListBox has no x:Name and I can't add the items in MainWindow, and with a separate class Tasks, I did the following (which doesn't work)
using System.Collections; // use ArrayList
using System.Collections.ObjectModel; // use Observable Collection
namespace FooApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class Tasks : ObservableCollection<Tasks>
{
string TaskName;
string Description;
int Priority;
public TasksStuff(string taskName, string description, int priority)
{
this.taskName = TaskName;
this.description = Description;
this.priority = Priority;
}
public string TaskName
{get{return this.taskName}}
public string Description
{get{return this.description}}
public string Priority
{get{return this.priority}}
private ArrayList Tasks
{
ArrayList taskList = new ArrayList();
taskList.Add( new TasksStuff("A foo task", "doing foo",1));
return taskList;
}
}
}
I am really confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该是
Tasks
的定义,以便您的示例正常工作:--编辑--
This should be the definition of
Tasks
for your sample to work correctly:--EDIT--