<legend id='AvRbY'><style id='AvRbY'><dir id='AvRbY'><q id='AvRbY'></q></dir></style></legend>

<small id='AvRbY'></small><noframes id='AvRbY'>

    • <bdo id='AvRbY'></bdo><ul id='AvRbY'></ul>

      1. <tfoot id='AvRbY'></tfoot>
        <i id='AvRbY'><tr id='AvRbY'><dt id='AvRbY'><q id='AvRbY'><span id='AvRbY'><b id='AvRbY'><form id='AvRbY'><ins id='AvRbY'></ins><ul id='AvRbY'></ul><sub id='AvRbY'></sub></form><legend id='AvRbY'></legend><bdo id='AvRbY'><pre id='AvRbY'><center id='AvRbY'></center></pre></bdo></b><th id='AvRbY'></th></span></q></dt></tr></i><div id='AvRbY'><tfoot id='AvRbY'></tfoot><dl id='AvRbY'><fieldset id='AvRbY'></fieldset></dl></div>

        WPF/C# 将自定义对象列表数据绑定到 ListBox?

        WPF/C# Binding custom object list data to a ListBox?(WPF/C# 将自定义对象列表数据绑定到 ListBox?)
          • <bdo id='od7Zj'></bdo><ul id='od7Zj'></ul>
              <tbody id='od7Zj'></tbody>
            1. <small id='od7Zj'></small><noframes id='od7Zj'>

              <i id='od7Zj'><tr id='od7Zj'><dt id='od7Zj'><q id='od7Zj'><span id='od7Zj'><b id='od7Zj'><form id='od7Zj'><ins id='od7Zj'></ins><ul id='od7Zj'></ul><sub id='od7Zj'></sub></form><legend id='od7Zj'></legend><bdo id='od7Zj'><pre id='od7Zj'><center id='od7Zj'></center></pre></bdo></b><th id='od7Zj'></th></span></q></dt></tr></i><div id='od7Zj'><tfoot id='od7Zj'></tfoot><dl id='od7Zj'><fieldset id='od7Zj'></fieldset></dl></div>
                <tfoot id='od7Zj'></tfoot>

                  <legend id='od7Zj'><style id='od7Zj'><dir id='od7Zj'><q id='od7Zj'></q></dir></style></legend>
                1. 本文介绍了WPF/C# 将自定义对象列表数据绑定到 ListBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 WPF 中将自定义对象列表的数据绑定到 ListBox 时,我遇到了一些困难.

                  I've ran into a bit of a wall with being able to bind data of my custom object list to a ListBox in WPF.

                  这是自定义对象:

                  public class FileItem
                  {
                      public string Name { get; set; }
                      public string Path { get; set; }
                  }
                  

                  这是列表:

                  private List<FileItem> folder = new List<FileItem>();
                  public List<FileItem> Folder { get { return folder; } }
                  

                  当文件被移动、删除、重命名等时,列表由 FileSystemWatcher 填充和维护.列表所做的只是跟踪名称和路径.

                  The list gets populated and maintained by a FileSystemWatcher as files get moved around, deleted, renamed, etc. All the list does is keeps tracks of names and paths.

                  这是我在 MainWindow 代码隐藏文件中的内容(目前为了测试目的而对其进行了硬编码):

                  Here's what I have in the MainWindow code-behind file (it's hard coded for testing purposes for now):

                  FolderWatcher folder1 = new FolderWatcher();
                  folder1.Run(@"E:MyApp	est", "*.txt");
                  
                  listboxFolder1.ItemsSource = folder1.Folder;
                  

                  这是我的 XAML 部分:

                  Here's my XAML portion:

                  <ListBox x:Name="listboxFolder1" Grid.Row="1" BorderThickness="0" 
                           ItemsSource="{Binding}"/>
                  

                  不幸的是,唯一显示的是每个条目的 MyApp.FileItem.如何显示名称等特定属性?

                  Unfortunately, the only thing that gets displayed is MyApp.FileItem for every entry. How do I display the specific property such as name?

                  推荐答案

                  你需要为你的 ListBox 定义 ItemTemplate

                  You will need to define the ItemTemplate for your ListBox

                      <ListBox x:Name="listboxFolder1" Grid.Row="1" BorderThickness="0" 
                       ItemsSource="{Binding}">
                         <ListBox.ItemTemplate>
                           <DataTemplate>
                             <TextBlock Text="{Binding Name}"/>
                           </DataTemplate>
                         </ListBox.ItemTemplate>
                       </ListBox>
                  

                  这篇关于WPF/C# 将自定义对象列表数据绑定到 ListBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                    <tbody id='AWEqa'></tbody>
                    • <legend id='AWEqa'><style id='AWEqa'><dir id='AWEqa'><q id='AWEqa'></q></dir></style></legend>
                      <tfoot id='AWEqa'></tfoot>

                      <i id='AWEqa'><tr id='AWEqa'><dt id='AWEqa'><q id='AWEqa'><span id='AWEqa'><b id='AWEqa'><form id='AWEqa'><ins id='AWEqa'></ins><ul id='AWEqa'></ul><sub id='AWEqa'></sub></form><legend id='AWEqa'></legend><bdo id='AWEqa'><pre id='AWEqa'><center id='AWEqa'></center></pre></bdo></b><th id='AWEqa'></th></span></q></dt></tr></i><div id='AWEqa'><tfoot id='AWEqa'></tfoot><dl id='AWEqa'><fieldset id='AWEqa'></fieldset></dl></div>

                          <bdo id='AWEqa'></bdo><ul id='AWEqa'></ul>
                          • <small id='AWEqa'></small><noframes id='AWEqa'>