From a6b7a2e8164938308b2fd8cd1685128a076f88e0 Mon Sep 17 00:00:00 2001 From: liufei Date: Fri, 9 Jul 2021 17:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BB=8Eusercontrol=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Control/UserControls/IconFont/IconPannel.xaml | 2 +- .../UserControls/IconFont/IconPannel.xaml.cs | 35 ++++++++++++++++++- Control/Windows/IconfontWindow.xaml | 4 +-- Control/Windows/IconfontWindow.xaml.cs | 30 +++++++++++----- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/Control/UserControls/IconFont/IconPannel.xaml b/Control/UserControls/IconFont/IconPannel.xaml index 9de1c89..8f7e0ed 100644 --- a/Control/UserControls/IconFont/IconPannel.xaml +++ b/Control/UserControls/IconFont/IconPannel.xaml @@ -8,7 +8,7 @@ mc:Ignorable="d" > - + diff --git a/Control/UserControls/IconFont/IconPannel.xaml.cs b/Control/UserControls/IconFont/IconPannel.xaml.cs index c75b18b..ace800e 100644 --- a/Control/UserControls/IconFont/IconPannel.xaml.cs +++ b/Control/UserControls/IconFont/IconPannel.xaml.cs @@ -1,4 +1,5 @@ -using System; +using GeekDesk.ViewModel; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -25,5 +26,37 @@ namespace GeekDesk.Control.UserControls.IconFont InitializeComponent(); } + public static readonly DependencyProperty IconfontListProperty = DependencyProperty.Register("IconfontList", typeof(List), typeof(IconPannel)); + public List IconfontList + { + get + { + return (List)GetValue(IconfontListProperty); + } + set + { + SetValue(IconfontListProperty, true); + } + } + + public static readonly DependencyProperty IconInfoProperty = DependencyProperty.Register("IconInfo", typeof(IconfontInfo), typeof(IconPannel)); + + public IconfontInfo IconInfo + { + get + { + return (IconfontInfo)GetValue(IconInfoProperty); + } + set + { + SetValue(IconInfoProperty, true); + } + } + + private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + IconfontInfo info = IconfontList[IconListBox.SelectedIndex]; + IconInfo = info; + } } } diff --git a/Control/Windows/IconfontWindow.xaml b/Control/Windows/IconfontWindow.xaml index 40eea77..c1a7d41 100644 --- a/Control/Windows/IconfontWindow.xaml +++ b/Control/Windows/IconfontWindow.xaml @@ -21,12 +21,12 @@ - + - + diff --git a/Control/Windows/IconfontWindow.xaml.cs b/Control/Windows/IconfontWindow.xaml.cs index 8717a5f..99c4a64 100644 --- a/Control/Windows/IconfontWindow.xaml.cs +++ b/Control/Windows/IconfontWindow.xaml.cs @@ -22,16 +22,19 @@ namespace GeekDesk.Control.Windows public partial class IconfontWindow : Window { - private static List listInfo; private static MenuInfo menuInfo; + private DataContextInfo dataContextInfo = new DataContextInfo(); + private IconfontWindow(List listInfo, MenuInfo menuInfo) { InitializeComponent(); - this.DataContext = listInfo; - IconfontWindow.listInfo = listInfo; + dataContextInfo.iconListSystem = listInfo; + this.DataContext = dataContextInfo; IconfontWindow.menuInfo = menuInfo; } + + /// /// 移动窗口 /// @@ -52,7 +55,7 @@ namespace GeekDesk.Control.Windows private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { - this.DataContext = listInfo; + //this.DataContext = listInfo; } private void Confirm_Click(object sender, RoutedEventArgs e) @@ -62,15 +65,15 @@ namespace GeekDesk.Control.Windows switch (tag) { case "Custom": - if (Custom.IconfontList.SelectedIndex != -1) + if (dataContextInfo.iconInfoCustom != null) { - menuInfo.MenuGeometry = (((StackPanel)Custom.IconfontList.SelectedItem).Tag as IconfontInfo).Text; + menuInfo.MenuGeometry = dataContextInfo.iconInfoCustom.Text; } break; default: - if (System.IconfontList.SelectedIndex != -1) + if (dataContextInfo.iconInfoSystem != null) { - menuInfo.MenuGeometry = (((StackPanel)System.IconfontList.SelectedItem).Tag as IconfontInfo).Text; + menuInfo.MenuGeometry = dataContextInfo.iconInfoSystem.Text; } break; } @@ -87,5 +90,16 @@ namespace GeekDesk.Control.Windows } window.Show(); } + + + private class DataContextInfo + { + public List iconListSystem; + public List iconListCustom; + public IconfontInfo iconInfoSystem; + public IconfontInfo iconInfoCustom; + + + } } } \ No newline at end of file