修改UI,添加单击行为,并绑定导航命令
修改文件:Mytodo.Views.IndexView.xaml ,在导航梯形添加内容
<DataTemplate>
<Border
Margin="10"
Background="{Binding Color}"
CornerRadius="5"
Opacity="0.9">
<Border.InputBindings>
<MouseBinding MouseAction="LeftClick"
Command="{Binding DataContext.NavigateCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}"
CommandParameter="{Binding}"/>
</Border.InputBindings>
添加导航命令,并初始化
修改文件:indexviewmodel.cs
/// <summary>
/// 导航命令
/// </summary>
public DelegateCommand<TaskBar> NavigateCommand { get;private set; }
NavigateCommand = new DelegateCommand<TaskBar>(Navigate);
添加导航区域变量,并初始化
修改文件:indexviewmodel.cs文章来源:https://www.toymoban.com/news/detail-618733.html
this.regionManager = provider.Resolve<IRegionManager>();
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<TaskBar>();
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方法
当为“已完成”栏时,使得显示的待办都为已完成。文章来源地址https://www.toymoban.com/news/detail-618733.html
public override void OnNavigatedTo(NavigationContext navigationContext)
{
base.OnNavigatedTo(navigationContext);
if (navigationContext.Parameters.ContainsKey("Value"))
SelectIndex = navigationContext.Parameters.GetValue<int>("Value");
else
SelectIndex = 0;
GetDataAsync();
}
到了这里,关于WPF实战学习笔记26-首页导航的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!