diff --git a/FileManager_UWP/Controls/LabelListControl.cs b/FileManager_UWP/Controls/LabelListControl.cs index fb9de19..a534451 100644 --- a/FileManager_UWP/Controls/LabelListControl.cs +++ b/FileManager_UWP/Controls/LabelListControl.cs @@ -1,4 +1,5 @@ -using System; +using FileManager_UWP.Model; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; @@ -46,7 +47,7 @@ namespace FileManager_UWP.Controls { //TextBlock textBlock = (TextBlock)GetTemplateChild("LabelTextBlock"); //textBlock.Text = "测试自定义控件\n"; //listView.ItemsSource = ItemsSource; - var itemsSource = ItemsSource as ObservableCollection; + var itemsSource = ItemsSource as ObservableCollection; //textBlock.Text += itemsSource.Count().ToString(); //labelListCanvas.Children.Count; @@ -56,15 +57,16 @@ namespace FileManager_UWP.Controls { _expand_story_board.Stop(); _expand_story_board.Children.Clear(); int expanded_position = 0; - foreach (string label in itemsSource) { + foreach (LabelItem label in itemsSource) { Button b = new Button(); - b.Content = label; - //b.SetValue(Canvas.LeftProperty, labelListCanvas.Children.Count * _collpse_distance); + b.Content = label.tag; + b.Background = new SolidColorBrush(label.color); b.SetValue(Canvas.LeftProperty, expanded_position); b.Style = (Style)genericResourceDictionary["LabelButtonStyle"]; + b.Click += B_Click; DoubleAnimation collpse_animate = new DoubleAnimation(); - collpse_animate.From = labelListCanvas.Children.Count * 22; + collpse_animate.From = null; // labelListCanvas.Children.Count * 22; collpse_animate.To = expanded_position; collpse_animate.Duration = _animate_during; collpse_animate.Completed += Animate_Completed; @@ -73,17 +75,24 @@ namespace FileManager_UWP.Controls { Storyboard.SetTargetProperty(collpse_animate, "(Canvas.Left)"); DoubleAnimation expand_animate = new DoubleAnimation(); - expand_animate.From = collpse_animate.To; - expand_animate.To = collpse_animate.From; + expand_animate.From = null; // expanded_position; + expand_animate.To = labelListCanvas.Children.Count * 22; expand_animate.Duration = _animate_during; expand_animate.Completed += Animate_Completed; _expand_story_board.Children.Add(expand_animate); Storyboard.SetTarget(expand_animate, b); Storyboard.SetTargetProperty(expand_animate, "(Canvas.Left)"); - expanded_position += label.Count() * 14 + 20; + expanded_position += label.tag.Count() * 14 + 20; labelListCanvas.Children.Add(b); } + measure(); + LabelListCanvas_PointerExited(null, null); + } + + private void B_Click(object sender, RoutedEventArgs e) { + Button b = sender as Button; + Debug.WriteLine(b.Content); } private void Animate_Completed(object sender, object e) { @@ -99,18 +108,14 @@ namespace FileManager_UWP.Controls { private void LabelListCanvas_PointerExited(object sender, PointerRoutedEventArgs e) { _expand_story_board.Begin(); - Debug.WriteLine(labelListCanvas.Width.ToString() + "," + labelListCanvas.Height.ToString()); } private void LabelListCanvas_PointerEntered(object sender, PointerRoutedEventArgs e) { _collpse_story_board.Begin(); - //labelListCanvas.Width = labelListCanvas.ActualWidth; - //labelListCanvas.Height = 20; - Debug.WriteLine(labelListCanvas.Width.ToString() + "," + labelListCanvas.Height.ToString()); } private void init() { - var itemsSource = ItemsSource as ObservableCollection; + var itemsSource = ItemsSource as ObservableCollection; itemsSource.CollectionChanged += ItemsSource_CollectionChanged; Button labelListButton = (Button)GetTemplateChild("LabelListPresenter"); labelListButton.PointerEntered += LabelListCanvas_PointerEntered; diff --git a/FileManager_UWP/Controls/LabelListControl.xaml b/FileManager_UWP/Controls/LabelListControl.xaml index e340152..919a4be 100644 --- a/FileManager_UWP/Controls/LabelListControl.xaml +++ b/FileManager_UWP/Controls/LabelListControl.xaml @@ -7,9 +7,9 @@ - + diff --git a/FileManager_UWP/Model/LabelItem.cs b/FileManager_UWP/Model/LabelItem.cs new file mode 100644 index 0000000..a0fd1d3 --- /dev/null +++ b/FileManager_UWP/Model/LabelItem.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using Windows.UI; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FileManager_UWP.Model { + public class LabelItem { + public string tag; + public Color color = Color.FromArgb(0xf0, 0xC6, 0xE2, 0xFF); + public LabelItem(string tag) { + this.tag = tag; + } + } +} diff --git a/FileManager_UWP/View/TestLabelView.xaml.cs b/FileManager_UWP/View/TestLabelView.xaml.cs index 24150f2..f6f4af3 100644 --- a/FileManager_UWP/View/TestLabelView.xaml.cs +++ b/FileManager_UWP/View/TestLabelView.xaml.cs @@ -1,4 +1,5 @@ -using System; +using FileManager_UWP.Model; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; @@ -22,8 +23,15 @@ namespace FileManager_UWP.View { /// An empty page that can be used on its own or navigated to within a Frame. /// public sealed partial class TestLabelView: Page { - public ObservableCollection Labels = new ObservableCollection{ - "照片", "土耳其摔跤", "李若明", "鸢晓曼", "才明洋与吴岳江进行土耳其摔跤", "真正的瑜伽大师"}; + public ObservableCollection Labels = + new ObservableCollection{ + new LabelItem("照片"), + new LabelItem("土耳其摔跤"), + new LabelItem("李若明"), + new LabelItem("鸢晓曼"), + new LabelItem("才明洋与吴岳江进行土耳其摔跤"), + new LabelItem("真正的瑜伽大师") + }; public TestLabelView() { this.InitializeComponent(); @@ -33,19 +41,19 @@ namespace FileManager_UWP.View { private void Button_Click(object sender, RoutedEventArgs e) { switch (Labels.Count) { case 0: - Labels.Add("照片"); + Labels.Add(new LabelItem("照片")); break; case 1: - Labels.Add("土耳其摔跤"); + Labels.Add(new LabelItem("土耳其摔跤")); break; case 2: - Labels.Add("李若明"); + Labels.Add(new LabelItem("李若明")); break; case 3: - Labels.Add("鸢晓曼"); + Labels.Add(new LabelItem("鸢晓曼")); break; default: - Labels.Add("才明洋与吴岳江摔跤"); + Labels.Add(new LabelItem("才明洋与吴岳江摔跤")); break; } Debug.WriteLine(Labels.Count.ToString());