我想绑定我的类属性之一。我在FileList.DataContext = fileManager;
下面做,我把代码隐藏了。
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.