我想绑定我的类属性之一。我是用FileList.DataContext = fileManager;
做的
下面我把codebehind。
C#
public class File : ListBoxItem
{
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
private string id;
public string Id
{
get { return this.id; }
set { this.id = value; }
}
}
public class FilesManager
{
public ObservableCollection<File> Files { get; set; }
public FilesManager()
{
Files = new ObservableCollection<File>();
}
}
XAML
<ListBox Name="FileList" Width="auto" Height="578" ItemsSource="{Binding Files, Mode=OneWay}" Tap="FileList_Tap" FontSize="36" Margin="0,14,0,15">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
当应用程序启动时,数据被分配,之后我得到Application_UnhandledException,然后绑定很棒。我做错了什么?
更新
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}//here debugger stops.
答案 0 :(得分:0)
您不需要从ListBoxItem继承您的类,因为您使用的是ItemTemplate。
使用简单类并将其绑定到列表中。
public class File
{
private string name;
public string Name
{
get { return this.name; }
set { this.name = value; }
}
private string id;
public string Id
{
get { return this.id; }
set { this.id = value; }
}
}