列表视图绑定有效,但未显示任何内容 [英] List view binding working but nothing is displayed

查看:73
本文介绍了列表视图绑定有效,但未显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在填充列表的列表视图.当我放一个消息框来告诉我列表视图的数量时,它给了我正确的答案,因此列表视图已被填充,但是什么也没有显示.

这是绑定的代码.

I have a list view that is being filled with a list. when i put a messagebox to tell me count of the list view it is giving me the correct answer so the listview is being filled, but nothing is displayed.

this is the code of the binding.

<ListView  ItemsSource="{Binding UsageProfilesList}" Grid.Row="1"   HorizontalAlignment="Stretch" x:Name="usageProfileLists123" >
                    <ListView.ItemTemplate>
                          <DataTemplate>
                              <Border Margin="0,10,0,10" PreviewMouseLeftButtonDown="StartDragging" PreviewMouseMove="Drag" HorizontalAlignment="Stretch"

                                  MouseLeftButtonDown="AddItemToTimeline" Tag="{Binding}" Background="Transparent">
                                  <TextBlock Text="{Binding Name}" FontSize="18" HorizontalAlignment="Center" />
                              </Border>
                          </DataTemplate>
                      </ListView.ItemTemplate>

              </ListView>



并且listview123正在填充.我在做什么错?



and listview123 is being filled. what am i doing wrong?

推荐答案

从一些简单的事情开始,然后向上移动.看看:

此..

使用以下ListView:

Start with something easier and move up. Take a look at:

This..

Use the following ListView:

<listview x:name="lst_Example" xmlns:x="#unknown">
   <listview.view>
      <gridview>
         <gridviewcolumn width="140" header="Column 1" />
      </gridview>
   </listview.view>
</listview>



然后,尝试使用以下代码从列表中填充项目:



Then, try the following code to populate it with items from a list:

private void FillMyList()
{
   List<string> theList = new System.Collections.Generic.List<string>();
   theList.Add("Item1");
   theList.Add("Item2");
   theList.Add("Item3");
   theList.Add("Item4");
   theList.Add("Item5");
   theList.Add("Item6");

   foreach (var item in theList)
   {
      lst_Example.Items.Add(item);
   }
}</string></string>


问题可能出在BORDER的边缘.

The problem could be from the margin of the BORDER.

<Border Margin="0,10,0,10" PreviewMouseLeftButtonDown="StartDragging" PreviewMouseMove="Drag" HorizontalAlignment="Stretch"

                                  MouseLeftButtonDown="AddItemToTimeline" Tag="{Binding}" Background="Transparent">
                                  <TextBlock Text="{Binding Name}" FontSize="18" HorizontalAlignment="Center" />
                              </Border>



删除页边距,然后尝试.


如果有帮助,请将其标记为答案



Remove the margin and try.


Mark it as answer if it is helpful


这篇关于列表视图绑定有效,但未显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆