msdn ( http://msdn.microsoft.com/en-us/library/ms742521.aspx#defining_simple_datatemplate )の例を理解したいと思います。
XAML コード:
<ListBox Width="400" Margin="10" ItemsSource="{Binding Source={StaticResource MyTodoList}}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=TaskName}" />
<TextBlock Text="{Binding Path=Description}"/>
<TextBlock Text="{Binding Path=Priority}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
テキスト ブロック内のデータはオブジェクトのプロパティですが、これでよろしいですか? オブジェクトは、コード ビハインド ファイルのリスト (?) myTodoList にありますか?
protected ObservableCollection<TODO> _myTodoList= new ObservableCollection<TODO>();
public ObservableCollection<TODO> MyTodoList
{
get { return _myTodoList; }
}
TODO を追加する
TODO t1 = new TODO();
t1.TaskName = "TaskName1";
t1.Description = "Description1";
t1.Priority = "Priority1";
_myTodoList.Add(t1);
TODO t2 = new TODO();
t2.TaskName = "TaskName2";
t2.Description = "Description2";
t2.Priority = "Priority2";
_myTodoList.Add(t2);
私のテスト TODO クラス:
public class TODO
{
public string TaskName { get; set; }
public string Description { get; set; }
public string Priority { get; set; }
}
しかし、コードは例外をスローします...
どうしたの?