diff --git a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj index a66f969a..f33f4a05 100644 --- a/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj +++ b/BPASmartClient.CustomResource/BPASmartClient.CustomResource.csproj @@ -199,10 +199,6 @@ - - - - diff --git a/BPASmartClient.CustomResource/Properties/AssemblyInfo.cs b/BPASmartClient.CustomResource/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..feac6732 --- /dev/null +++ b/BPASmartClient.CustomResource/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +using System.Runtime.InteropServices; + +[assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)] + +// 在此类的 SDK 样式项目中,现在,在此文件中早前定义的几个程序集属性将在生成期间自动添加,并使用在项目属性中定义的值进行填充。有关包含的属性以及如何定制此过程的详细信息,请参阅 +// https://aka.ms/assembly-info-properties + + +// 将 ComVisible 设置为 false 会使此程序集中的类型对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,请将该类型的 ComVisible +// 属性设置为 true。 + +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID。 + +[assembly: Guid("ad425ef8-378d-4499-b279-09b566451a3e")] diff --git a/BPASmartClient.CustomResource/RecDictionarys/RecIcoButtonStyle.xaml b/BPASmartClient.CustomResource/RecDictionarys/RecIcoButtonStyle.xaml index 0fdfd72a..d130cd8b 100644 --- a/BPASmartClient.CustomResource/RecDictionarys/RecIcoButtonStyle.xaml +++ b/BPASmartClient.CustomResource/RecDictionarys/RecIcoButtonStyle.xaml @@ -1,5 +1,9 @@ - + + + + + + \ No newline at end of file diff --git a/BPASmartClient.CustomResource/Themes/Generic.xaml b/BPASmartClient.CustomResource/Themes/Generic.xaml new file mode 100644 index 00000000..8a865803 --- /dev/null +++ b/BPASmartClient.CustomResource/Themes/Generic.xaml @@ -0,0 +1,46 @@ + + + + + + + \ No newline at end of file diff --git a/BPASmartClient.CustomResource/UserControls/IcoButton.cs b/BPASmartClient.CustomResource/UserControls/IcoButton.cs new file mode 100644 index 00000000..ddec3c05 --- /dev/null +++ b/BPASmartClient.CustomResource/UserControls/IcoButton.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace BPASmartClient.CustomResource.UserControls +{ + /// + /// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。 + /// + /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。 + /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 + /// 元素中: + /// + /// xmlns:MyNamespace="clr-namespace:BPASmartClient.CustomResource.UserControls" + /// + /// + /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。 + /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 + /// 元素中: + /// + /// xmlns:MyNamespace="clr-namespace:BPASmartClient.CustomResource.UserControls;assembly=BPASmartClient.CustomResource.UserControls" + /// + /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用, + /// 并重新生成以避免编译错误: + /// + /// 在解决方案资源管理器中右击目标项目,然后依次单击 + /// “添加引用”->“项目”->[浏览查找并选择此项目] + /// + /// + /// 步骤 2) + /// 继续操作并在 XAML 文件中使用控件。 + /// + /// + /// + /// + public class IcoButton : Control + { + static IcoButton() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(IcoButton), new FrameworkPropertyMetadata(typeof(IcoButton))); + } + + private Brush tempBackground; + + private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + (d as IcoButton)?.Refresh(); + } + + private void Refresh() + { + tempBackground = this.Background; + } + + public Action Command + { + get { return (Action)GetValue(CommandProperty); } + set { SetValue(CommandProperty, value); } + } + public static readonly DependencyProperty CommandProperty = + DependencyProperty.Register("Command", typeof(Action), typeof(IcoButton), + new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged))); + + public string Content + { + get { return (string)GetValue(ContentProperty); } + set { SetValue(ContentProperty, value); } + } + public static readonly DependencyProperty ContentProperty = + DependencyProperty.Register("Content", typeof(string), typeof(IcoButton), + new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged))); + + public string IcoText + { + get { return (string)GetValue(IcoTextProperty); } + set { SetValue(IcoTextProperty, value); } + } + public static readonly DependencyProperty IcoTextProperty = + DependencyProperty.Register("IcoText", typeof(string), typeof(IcoButton), + new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged))); + + public Brush EnterBackground + { + get { return (Brush)GetValue(EnterBackgroundProperty); } + set { SetValue(EnterBackgroundProperty, value); } + } + public static readonly DependencyProperty EnterBackgroundProperty = + DependencyProperty.Register("EnterBackground", typeof(Brush), typeof(IcoButton), + new PropertyMetadata(Brushes.DarkGray, new PropertyChangedCallback(OnPropertyChanged))); + + + public Brush PressedBackground + { + get { return (Brush)GetValue(PressedBackgroundProperty); } + set { SetValue(PressedBackgroundProperty, value); } + } + public static readonly DependencyProperty PressedBackgroundProperty = + DependencyProperty.Register("PressedBackground", typeof(Brush), typeof(IcoButton), + new PropertyMetadata(Brushes.Gray, new PropertyChangedCallback(OnPropertyChanged))); + + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + var icon = base.GetTemplateChild("PART_icoText") as TextBlock; + var content = base.GetTemplateChild("PART_content") as TextBlock; + var gr = base.GetTemplateChild("PART_gr") as Grid; + + if (icon != null) + { + Binding binding = new Binding("IcoText"); + binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; + binding.RelativeSource = new RelativeSource() { AncestorType = typeof(IcoButton), Mode = RelativeSourceMode.FindAncestor }; + icon.SetBinding(TextBlock.TextProperty, binding); + } + + if (content != null) + { + Binding binding = new Binding("Content"); + binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; + binding.RelativeSource = new RelativeSource() { AncestorType = typeof(IcoButton), Mode = RelativeSourceMode.FindAncestor }; + content.SetBinding(TextBlock.TextProperty, binding); + } + + if (gr != null) + { + gr.MouseLeftButtonDown += Gr_MouseLeftButtonDown; + gr.MouseEnter += Gr_MouseEnter; + gr.MouseLeave += Gr_MouseLeave; + } + } + + /// + /// 鼠标离开颜色 + /// + /// + /// + private void Gr_MouseLeave(object sender, MouseEventArgs e) + { + //VisualStateManager.GoToState(this, "Leave", true); + this.Background = tempBackground; + } + + /// + /// 鼠标进入颜色 + /// + /// + /// + private void Gr_MouseEnter(object sender, MouseEventArgs e) + { + //VisualStateManager.GoToState(this, "Enter", true); + this.Background = EnterBackground; + } + + private void Gr_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (Command != null) Command(); + this.Background = PressedBackground; + } + + } +} diff --git a/BPASmartClient.CustomResource/UserControls/IcoButton.xaml b/BPASmartClient.CustomResource/UserControls/IcoButton.xaml deleted file mode 100644 index b259e938..00000000 --- a/BPASmartClient.CustomResource/UserControls/IcoButton.xaml +++ /dev/null @@ -1,69 +0,0 @@ - diff --git a/BPASmartClient.CustomResource/UserControls/IcoButton.xaml.cs b/BPASmartClient.CustomResource/UserControls/IcoButton.xaml.cs deleted file mode 100644 index f6de63ee..00000000 --- a/BPASmartClient.CustomResource/UserControls/IcoButton.xaml.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace BPASmartClient.CustomResource.UserControls -{ - /// - /// IcoButton.xaml 的交互逻辑 - /// - public partial class IcoButton : Button - { - public IcoButton() - { - InitializeComponent(); - } - - public static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - (d as IcoButton).Refresh(); - } - - private void Refresh() - { - this.ico.Text = IcoText; - this.con.Text = Context; - - this.ico.FontSize = PryFontSize; - this.con.FontSize = PryFontSize; - - this.ico.Foreground = PryForeground; - this.con.Foreground = PryForeground; - - } - - - public Brush PryForeground - { - get { return (Brush)GetValue(PryForegroundProperty); } - set { SetValue(PryForegroundProperty, value); } - } - public static readonly DependencyProperty PryForegroundProperty = - DependencyProperty.Register("PryForeground", typeof(Brush), typeof(IcoButton), - new PropertyMetadata(default, new PropertyChangedCallback(OnPropertyChanged))); - - - public double PryFontSize - { - get { return (double)GetValue(PryFontSizeProperty); } - set { SetValue(PryFontSizeProperty, value); } - } - public static readonly DependencyProperty PryFontSizeProperty = - DependencyProperty.Register("PryFontSize", typeof(double), typeof(IcoButton), - new PropertyMetadata(12, new PropertyChangedCallback(OnPropertyChanged))); - - - public string IcoText - { - get { return (string)GetValue(IcoTextProperty); } - set { SetValue(IcoTextProperty, value); } - } - public static readonly DependencyProperty IcoTextProperty = - DependencyProperty.Register("IcoText", typeof(string), typeof(IcoButton), - new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged))); - - - public string Context - { - get { return (string)GetValue(ContextProperty); } - set { SetValue(ContextProperty, value); } - } - public static readonly DependencyProperty ContextProperty = - DependencyProperty.Register("Context", typeof(string), typeof(IcoButton), - new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged))); - - - } -} diff --git a/BPASmartClient/Control/ShopDeviceConfigView.xaml b/BPASmartClient/Control/ShopDeviceConfigView.xaml index 970ae881..44787ea3 100644 --- a/BPASmartClient/Control/ShopDeviceConfigView.xaml +++ b/BPASmartClient/Control/ShopDeviceConfigView.xaml @@ -76,7 +76,7 @@ - + @@ -95,15 +95,14 @@ Style="{StaticResource ComboBoxStyle}" Text="{Binding ClientDeviceType}" /> - + + Style="{StaticResource NewButtonStyle}" />