Repository navigation
Expand file tree
/
Copy pathAllPathIconExample.xaml.cs
More file actions
101 lines (87 loc) · 3.47 KB
/
Copy pathAllPathIconExample.xaml.cs
File metadata and controls
101 lines (87 loc) · 3.47 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using WPFDevelopers.Controls;
using WPFDevelopers.Helpers;
using ListBox = System.Windows.Controls.ListBox;
namespace WPFDevelopers.Samples.ExampleViews
{
/// <summary>
/// AllPathIconExample.xaml 的交互逻辑
/// </summary>
public partial class AllPathIconExample : UserControl
{
string PathIconXaml = " <wd:PathIcon Kind=\"{0}\" />";
public List<PackIconKind> AllPathIcon
{
get { return (List<PackIconKind>)GetValue(AllPathIconProperty); }
set { SetValue(AllPathIconProperty, value); }
}
public static readonly DependencyProperty AllPathIconProperty =
DependencyProperty.Register("AllPathIcon", typeof(List<PackIconKind>), typeof(AllPathIconExample), new PropertyMetadata(null));
public string PathIconText
{
get { return (string)GetValue(PathIconTextProperty); }
set { SetValue(PathIconTextProperty, value); }
}
public static readonly DependencyProperty PathIconTextProperty =
DependencyProperty.Register("PathIconText", typeof(string), typeof(AllPathIconExample), new PropertyMetadata(null));
public Geometry Data
{
get { return (Geometry)GetValue(DataProperty); }
set { SetValue(DataProperty, value); }
}
public static readonly DependencyProperty DataProperty =
DependencyProperty.Register("Data", typeof(Geometry), typeof(AllPathIconExample), new PropertyMetadata(null));
public AllPathIconExample()
{
InitializeComponent();
DataContext = this;
Loaded += OnAllPathIconExample_Loaded;
}
private void OnAllPathIconExample_Loaded(object sender, RoutedEventArgs e)
{
var iconList = new List<PackIconKind>();
foreach (PackIconKind iconKind in Enum.GetValues(typeof(PackIconKind)))
{
iconList.Add(iconKind);
}
AllPathIcon = new List<PackIconKind>(iconList);
}
private void OnPathIconSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0 && sender is ListBox listBox)
{
var kindValue = e.AddedItems[0].ToString();
PathIconText = string.Format(PathIconXaml, kindValue);
var selectedItem = e.AddedItems[0];
var listBoxItem = listBox.ItemContainerGenerator.ContainerFromItem(selectedItem) as ListBoxItem;
if (listBoxItem != null)
{
var pathIcon = WPFDevelopers.Helpers.ControlsHelper.FindVisualChild<PathIcon>(listBoxItem);
if (pathIcon != null)
Data = pathIcon.Data;
}
}
}
private void BtnCopy_Click(object sender, RoutedEventArgs e)
{
SetClipboard(PathIconText);
}
private void BtnCopyGeometry_Click(object sender, RoutedEventArgs e)
{
SetClipboard(Data?.ToString());
}
void SetClipboard(string text)
{
if (ClipboardHelper.TrySetText(text))
{
Toast.Push("已复制到剪贴板");
return;
}
Toast.Push("复制失败,请稍后重试", ToastImage.Error, true);
}
}
}