WPF实战学习笔记26-首页导航

修改UI,添加单击行为,并绑定导航命令

修改文件:Mytodo.Views.IndexView.xaml ,在导航梯形添加内容


    
        
            
        

添加导航命令,并初始化

修改文件:indexviewmodel.cs

/// 
/// 导航命令
/// 
public DelegateCommand NavigateCommand { get;private set; }
NavigateCommand = new DelegateCommand(Navigate);

添加导航区域变量,并初始化

修改文件:indexviewmodel.cs

this.regionManager = provider.Resolve();
private readonly IRegionManager regionManager;

添加导航方法

private void Navigate(TaskBar obj)
{
    if (string.IsNullOrWhiteSpace(obj.Target)) return;

    NavigationParameters param = new NavigationParameters();

    if (obj.Title == "已完成")
    {
        param.Add("Value", 1);
    }
    regionManager.Regions[PrismManager.MainViewRegionName].RequestNavigate(obj.Target, param);
}

TaskBars添加对应的导航区域

void CreatBars()
{
    Title = "您好,2022";
    TaskBars = new ObservableCollection();
    TaskBars.Add(new TaskBar { Icon = "CalendarBlankOutline", Title = "汇总", Color = "#FF00FF00", Content = "27", Target = "TodoView" });
    TaskBars.Add(new TaskBar { Icon = "CalendarMultipleCheck", Title = "已完成", Color = "#6B238E", Content = "24", Target = "TodoView" });
    TaskBars.Add(new TaskBar { Icon = "ChartLine", Title = "完成比例", Color = "#32CD99", Content = "100%", Target = "" });
    TaskBars.Add(new TaskBar { Icon = "CheckboxMarked", Title = "备忘录", Color = "#5959AB", Content = "13", Target = "MemoView" });
}

修改OnNavigate方法

当为“已完成”栏时,使得显示的待办都为已完成。

public override void OnNavigatedTo(NavigationContext navigationContext)
{
    base.OnNavigatedTo(navigationContext);
    if (navigationContext.Parameters.ContainsKey("Value"))
        SelectIndex = navigationContext.Parameters.GetValue("Value");
    else
        SelectIndex = 0;
    GetDataAsync();
}

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