1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
   | using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
using ListShow.Model;
 
namespace ListShow.ViewModel
{
    /// <summary>
    /// This class contains properties that the main View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            var colors = new Color[]
            {
                Colors.Brown,
                Colors.Red,
                Colors.Orange,
                Colors.Yellow,
                Colors.Green,
                Colors.Blue,
                Colors.Purple
            };
 
            var items = new ObservableCollection<CustomDataItem>();
            for (int i = 0; i < 20; ++i) items.Add(
                new CustomDataItem
                {
                    Text = $"Item {i}",
                    BackgroundColor = colors[i % colors.Length],
                    InnerColor = colors[(i + 3) % colors.Length]
                });
 
            Items = new CollectionView(items);
 
            Header = "Hello!";
        }
 
        public CollectionView Items { get; private set; }
 
        public ICommand CloseCommand { get; private set; } = new RelayCommand(() => Application.Current.Shutdown());
 
        private string _header;
        public string Header { get { return _header; } set { Set(ref _header, value); } }
    }
}
 
namespace ListShow.Model
{
    public class CustomDataItem
    {
        public string Text { get; set; }
        public Color BackgroundColor { get; set; }
        public Color InnerColor { get; set; }
    }
} | 
Partager