简体   繁体   English

Listview显示名称空间而不是类Phone 8.1运行时中的值

[英]Listview Displaying Name space not values from class Phone 8.1 Runtime

I am trying to bind a simple Listview control using the folloiwng 我正在尝试使用以下方法绑定一个简单的Listview控件

<ListView x:Name="listView" ItemsSource="{Binding}">

        <StackPanel Orientation="Horizontal" Width="292" Height="80">
        <Border Height="60" Width="60" Margin="10,10,0,10">
            <Image Source="/SampleImage.png" Stretch="UniformToFill"/>
        </Border>
        <StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="0,10,0,0">
            <TextBlock Text="{Binding description}" 
                       Margin="10,0,0,0" Width="180" Height="42" 
                       TextTrimming="WordEllipsis" TextWrapping="Wrap" HorizontalAlignment="Left"/>
            <TextBlock Text="{Binding Title}" 
                       Margin="10,2,0,0" Width="180" Height="14" 
                       TextTrimming="WordEllipsis" HorizontalAlignment="Left" 
                       FontSize="9" Opacity="0.49"/>
        </StackPanel>
            </StackPanel>

    </ListView>

But for some reason when I reference my list which is created as such using Parse; 但是由于某些原因,当我引用使用Parse这样创建的列表时; using System; 使用系统; using System.Collections.Generic; 使用System.Collections.Generic; using System.Collections.ObjectModel; 使用System.Collections.ObjectModel; using System.ComponentModel; 使用System.ComponentModel; using System.Linq; 使用System.Linq; using System.Threading.Tasks; 使用System.Threading.Tasks;

namespace Curo.DataModel
{
    public class curoLists : INotifyPropertyChanged
    {
        public curoLists()
        {

        }
        public curoLists(String uniqueId, String title, String subtitle, String imagePath, String description, String content, string type)
        {
            this.UniqueId = uniqueId;
            this.Title = title;
            this.Subtitle = subtitle;
            this.Description = description;
            this.ImagePath = imagePath;
            this.Content = content;
            this.Type = type;
        }


        public curoLists(String uniqueId, String title, String subtitle, String imagePath, String description, String content, bool unread, Int32 status)
        {
            UniqueId = uniqueId;
            Title = title;
            Subtitle = subtitle;
            Description = description;
            ImagePath = imagePath;
            Content = content;
            Unread = unread;
            Status = status;
        }


        private bool _unread;

        private string _title;
        public string UniqueId { get; private set; }
        public string Title
        {
            get { return _title; }

            set
            {
                _title = value;
                NotifyPropertyChanged("Title");
            }
        }
        public string Subtitle { get; private set; }
        public string Description { get; private set; }
        public string ImagePath { get; private set; }
        public string Content { get; private set; }
        public int Status { get; private set; }
        public string Type { get; private set; }

        public string ViewToUse { get; private set; }
        public bool Unread
        {
            get { return _unread; }
            set
            {
                _unread = value;
                NotifyPropertyChanged("Unread");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public static async Task<curoLists> CreateFromParseObject(ParseObject parseObject)
        {
            return await Task.Run<curoLists>(() =>
            {
                var mlist = new curoLists();

                mlist.Title = parseObject.ObjectId;
                if (parseObject.ContainsKey("name"))
                {
                    mlist.Title = (string)parseObject["name"];
                }


                if (parseObject.ContainsKey("description"))
                {
                    mlist.Description = (string)parseObject["description"];
                }
                if (parseObject.ContainsKey("image"))
                {
                    mlist.ImagePath = (string)parseObject["image"];
                }


                if (parseObject.ContainsKey("type"))
                {
                    string mtype = (string)parseObject["type"];

                    if (mtype == "N")
                    {
                        mlist.Type = "Notes";
                        mlist.ViewToUse = "Notes.Xaml";
                    }
                }
                return mlist;
            });
        }
    }

}

It does not display the requested data instead it just displays the folowing. 它不显示请求的数据,而仅显示以下信息。 I populate my list in the following mannor 我用以下方式填充列表

  List<curoLists> cLists;
  public  ClientsManage()
  {
      this.InitializeComponent();

      PopulatelistAsync();
  }

public async Task PopulatelistAsync()
    {
        try
        {
            curoListsDal _db = new curoListsDal();


            cLists = await _db.GetListsAync();

            listView.ItemsSource = cLists;


        }
        catch (Exception ex)
        {
        }

    }

But it just displays the name space and not the data Curo.DataModel.CuroLists. 但是它仅显示名称空间,而不显示数据Curo.DataModel.CuroLists。 When i debug the data it is def their and correct spelling the only thing it complains about when i compiles is on my constructor i do not have the await command but that would not make the data not appear would it?. 当我调试数据时,它是def他们的并且正确的拼写是我在编译时抱怨的唯一一件事是在我的构造函数上,我没有await命令,但是那不会使数据不出现,对吗?

ListView is single Column. ListView是单列。 So you must custom it with GridView. 因此,您必须使用GridView对其进行自定义。 I also add Window_Loaded method with asyn, and own Dal: 我还使用asyn添加Window_Loaded方法,并拥有自己的Dal:

XAML: XAML:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        Loaded="Window_Loaded">
    <ListView x:Name="listView">
        <ListView.View>
            <GridView>
                <GridViewColumn Width="140" Header="Game Name" 
              DisplayMemberBinding="{Binding Description}"  />
                <GridViewColumn Width="140" Header="Title"  
              DisplayMemberBinding="{Binding Title}" />
            </GridView>
        </ListView.View>
    </ListView>
</Window>

Code behind: 后面的代码:

public partial class MainWindow : Window
{
    private List<curoLists> cLists;

    public MainWindow()
    {
        InitializeComponent();
    }

    // decorate this method with asyn
    private async void Window_Loaded(
        object sender, RoutedEventArgs e)
    {
        await PopulatelistAsync();
    }

    public async Task PopulatelistAsync()
    {
        try
        {
            curoListsDal _db = new curoListsDal();
            cLists = await _db.GetListsAync();
            listView.ItemsSource = cLists;
        }
        catch (Exception ex)
        {
        }
    }
}

public class curoListsDal
{
    public async Task<List<curoLists>> GetListsAync()
    {
        return await
            Task.Run<List<curoLists>>(
                () =>
                {
                    Thread.Sleep(2000); // long run
                    var result = new List<curoLists>();
                    for (var i = 0; i < 3; i++)
                    {
                        var id = Guid.NewGuid().ToString();
                        var mlist = new curoLists(id,
                            "title" + id, "subtitle", "imagePath",
                            "desc", "content", true, 1);
                        result.Add(mlist);
                    }
                    return result;
                });
    }
}

Hope this help. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM