开发者

How do I define what goes into a ListView?

开发者 https://www.devze.com 2023-03-06 03:55 出处:网络
For example, I have this class: using System; using System.Collections.Generic; using System.Linq; using System.Text;

For example, I have this class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Text.RegularExpressions;

namespace GameLenseWpf.Entities
{
    public class Game
    {
        public Game()
        {
            IsValid = true;
        }

        //Property used to verify if the model is valid.
        public bool IsValid { get; set; }

        private string _releaseDate;
        public string ReleaseDate
        {
            get { return _releaseDate; }
            set
            {
                _releaseDate = Regex.Replace(value, @"\s+", " ").Trim();
            }
        }

        private string _pageUrl;
        public string PageUrl
        {
            get { return _pageUrl; }
            set
            {
                Uri uri;
                if (Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out uri))
                {
                    _pageUrl = uri.ToString();
                }
                else
                {
                    IsValid = false;
                }
            }
        }

        private string _imageUrl;
        public string ImageUrl
        {
            get
            {
                return _imageUrl;
            }

            set
            {
                Uri uri;
                if (Uri.TryCreate(value, UriKind.RelativeOrAbsolute, out uri))
                {
                    _imageUrl = uri.ToString();
                }
                else
                {
                    IsValid = false;
                }
            }
        }

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

            set
            {
                if (value.Length > 25)
                    _title = value.Substring(0, 25) + "...";
                else
                    _title = value;
            }
        }

        private string _synopsis;
        public string Synopsis
        {
            get
            {
                return _synopsis;
            }

            set
            {
                _synopsis = HttpUtility.HtmlDecode(value);
            }
        }
    }
}

And here's my XAML:

<ListView Grid.Row="1" Background="#343434">

</ListView>

How would I define a layout of the content开发者_Go百科s in this ListView? I'm porting a working Windows Forms application to WPF. In my Winforms, I have a UserControl that would display this information from my POCO, and I would add N amount of UserControls to a Panel.

Thanks for the suggestions.


This should be a good start:

    <ListView
        HorizontalAlignment="Stretch"
        VerticalAlignment="Stretch"
        Name="listView1">
        <ListView.View>
            <GridView>
                <GridViewColumn
                    Header="Release Date"
                    DisplayMemberBinding="{Binding Path=ReleaseDate}" />
                <GridViewColumn
                    Header="Title"
                    DisplayMemberBinding="{Binding Path=Title}" />
            </GridView>
        </ListView.View>
    </ListView>

You can assign listView1.ItemsSource in the code.

0

精彩评论

暂无评论...
验证码 换一张
取 消