Repository navigation
Expand file tree
/
Copy pathBreadCrumbBarExample.xaml.cs
More file actions
82 lines (71 loc) · 3.18 KB
/
Copy pathBreadCrumbBarExample.xaml.cs
File metadata and controls
82 lines (71 loc) · 3.18 KB
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
75
76
77
78
79
80
81
82
using System.Collections.Generic;
using System;
using System.Windows.Controls;
using System.Collections.ObjectModel;
using System.Windows;
using System.Reflection;
namespace WPFDevelopers.Samples.ExampleViews
{
/// <summary>
/// StepExample.xaml 的交互逻辑
/// </summary>
public partial class BreadCrumbBarExample : UserControl
{
private int index = 0;
private List<BreadcrumbItem> Breadcrumbs = new List<BreadcrumbItem>();
public ObservableCollection<BreadcrumbItem> BreadcrumbItems
{
get { return (ObservableCollection<BreadcrumbItem>)GetValue(BreadcrumbItemsProperty); }
set { SetValue(BreadcrumbItemsProperty, value); }
}
public static readonly DependencyProperty BreadcrumbItemsProperty =
DependencyProperty.Register("BreadcrumbItems", typeof(ObservableCollection<BreadcrumbItem>), typeof(BreadCrumbBarExample), new PropertyMetadata(null));
public BreadcrumbItem BreadcrumbItem
{
get { return (BreadcrumbItem)GetValue(BreadcrumbItemProperty); }
set { SetValue(BreadcrumbItemProperty, value); }
}
public static readonly DependencyProperty BreadcrumbItemProperty =
DependencyProperty.Register("BreadcrumbItem", typeof(BreadcrumbItem), typeof(BreadCrumbBarExample), new PropertyMetadata(null));
public BreadCrumbBarExample()
{
InitializeComponent();
Loaded += BreadCrumbBarExample_Loaded;
}
private void BreadCrumbBarExample_Loaded(object sender, RoutedEventArgs e)
{
var breadcrumbItems = new List<BreadcrumbItem>()
{
new BreadcrumbItem() { Text = "主页" , Uri=new Uri("pack://application:,,,/WPFDevelopers.Samples;component/ExampleViews/DrawerMenu/HomePage.xaml",UriKind.Absolute ) },
new BreadcrumbItem() { Text = "Edge", Uri=new Uri("pack://application:,,,/WPFDevelopers.Samples;component/ExampleViews/DrawerMenu/EdgePage.xaml" ,UriKind.Absolute ) },
new BreadcrumbItem() { Text = "邮件", Uri=new Uri("pack://application:,,,/WPFDevelopers.Samples;component/ExampleViews/DrawerMenu/EmailPage.xaml" ,UriKind.Absolute ) },
};
Breadcrumbs = breadcrumbItems;
myFrame.Navigate(Breadcrumbs[index].Uri);
BreadcrumbItems = new ObservableCollection<BreadcrumbItem>() { Breadcrumbs[index] };
}
private void BreadCrumbBar_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
myFrame.Navigate(BreadcrumbItem.Uri);
index = BreadcrumbItems.IndexOf(BreadcrumbItem);
}
private void btnNext_Click(object sender, RoutedEventArgs e)
{
index += 1;
if (index >= Breadcrumbs.Count) return;
var model = Breadcrumbs[index];
if (BreadcrumbItems.Contains(model))
{
BreadcrumbItem = model;
return;
}
BreadcrumbItems.Add(model);
BreadcrumbItem = model;
}
}
public class BreadcrumbItem
{
public string Text { get; set; }
public Uri Uri { get; set; }
}
}