WPF实战学习笔记05-首页界面

首页界面

新建文件

  • 添加文件[类型:用户控件]

    ./Common/Models/TaskBars.cs

    ./Common/Models/ToDoDto.cs

    ./Common/Models/MemoDto.cs

新建类

TaskBars.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Common.Models
{
    public class TaskBar
    {
        private string? title;
        private string? content;
        private string? target;
        private string? color;
        private string? icon;


		public string? Icon
		{
			get { return icon; }
			set { icon = value; }
		}

		

		public string? Title
		{
			get { return title; }
			set { title = value; }
		}

		

		public string? Content
		{
			get { return content; }
			set { content = value; }
		}

		

		public string? Color
		{
			get { return color; }
			set { color = value; }
		}

		

		public string? Target
		{
			get { return target; }
			set { target = value; }
		}
	}
}

TodoDto.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Common.Models
{
    public class ToDoDto:BaseTodo
    {
		private string? title;
		private string? content;
		private int status;

		public int Status
		{
			get { return status; }
			set { status = value; }
		}

		public string? Content
		{
			get { return content; }
			set { content = value; }
		}

		public string? Title
		{
			get { return title; }
			set { title = value; }
		}
	}
}

MemoDto.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Common.Models
{
    /// 
    /// 备忘录
    /// 
    public class MemoDto:BaseTodo
    {
        private string? title;
        private string? content;
        private int status;

        public int Status
        {
            get { return status; }
            set { status = value; }
        }

        public string? Content
        {
            get { return content; }
            set { content = value; }
        }

        public string? Title
        {
            get { return title; }
            set { title = value; }
        }
    }
}

BaseTodo.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mytodo.Common.Models
{
    public   class BaseTodo
    {
		private int id;
		private DateTime createDate;
		private DateTime updateDate;

		/// 
		/// 项修改日期
		/// 
		public DateTime UpdateDate
		{
			get { return updateDate; }
			set { updateDate = value; }
		}

		/// 
		/// 项创建时间
		/// 
		public DateTime CreateDate
		{
			get { return createDate; }
			set { createDate = value; }
		}

		/// 
		/// 项ID
		/// 
		public int Id
		{
			get { return id; }
			set { id = value; }
		}
	}
}

创建TaskBars集合变量并初始化

创建变量

  • IndexViewModel

    private ObservableCollection taskBars;
    

初始化

  • IndexViewModel(代码在构造函数中)
TaskBars=new ObservableCollection();
TaskBars.Add(new TaskBar { Icon = "CalendarBlankOutline", Title = "汇总", Color = "#FF00FF00", Content = "27", Target = "" });
TaskBars.Add(new TaskBar { Icon = "CalendarMultipleCheck", Title = "已完成", Color = "#6B238E", Content = "24", Target = "" });
TaskBars.Add(new TaskBar { Icon = "ChartLine", Title = "完成比例", Color = "#32CD99", Content = "100%", Target = "" });
TaskBars.Add(new TaskBar { Icon = "CheckboxMarked", Title = "备忘录", Color = "#5959AB", Content = "13", Target = "" });

创建todoDtos、memoDtos集合变量并初始化

  • IndexViewModel

    private ObservableCollection todoDtos;
    private ObservableCollection memoDtos;
    public ObservableCollection MemoDtos
    {
        get { return memoDtos; }
        set { memoDtos = value; RaisePropertyChanged(); }
    }
    
    
    public ObservableCollection TodoDtos
    {
        get { return todoDtos; }
        set { todoDtos = value; RaisePropertyChanged(); }
    }
    void CreatTestData()
    {
        TodoDtos = new ObservableCollection();
        MemoDtos = new ObservableCollection();
    
        for (int i = 0; i < 20; i++)
        {
            TodoDtos.Add(new ToDoDto() { Title = "待办" + i, Content = "正在处理中....." });
            MemoDtos.Add(new MemoDto() { Title = "备忘" + i, Content = "正在忘记中....." });
        }
    }
    public IndexViewModel()
    {
        Title = "您好,2022";
        TaskBars=new ObservableCollection();
        TaskBars.Add(new TaskBar { Icon = "CalendarBlankOutline", Title = "汇总", Color = "#FF00FF00", Content = "27", Target = "" });
        TaskBars.Add(new TaskBar { Icon = "CalendarMultipleCheck", Title = "已完成", Color = "#6B238E", Content = "24", Target = "" });
        TaskBars.Add(new TaskBar { Icon = "ChartLine", Title = "完成比例", Color = "#32CD99", Content = "100%", Target = "" });
        TaskBars.Add(new TaskBar { Icon = "CheckboxMarked", Title = "备忘录", Color = "#5959AB", Content = "13", Target = "" });
    
        CreatTestData();
    }
    

定义界面


    
        
            
            
            
        
        
        
            
                
                    
                
            
            
                
                    
                        
                            
                        
                        
                            
                                
                                
                                
                            
                            
                                
                                
                            
                        
                    
                
            
        
        
            
                
                
            
            
            
            
                
                    
                    

你可能感兴趣的:(WPF实战学习笔记,wpf,学习,笔记)