diff --git a/DeedyDesigner/Deedy.Testing/ElegantWindow.cs b/DeedyDesigner/Deedy.Testing/ElegantWindow.cs new file mode 100644 index 0000000..be84e57 --- /dev/null +++ b/DeedyDesigner/Deedy.Testing/ElegantWindow.cs @@ -0,0 +1,61 @@ +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 Deedy.Testing +{ + /// + /// 按照步骤 1a 或 1b 操作,然后执行步骤 2 以在 XAML 文件中使用此自定义控件。 + /// + /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。 + /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 + /// 元素中: + /// + /// xmlns:MyNamespace="clr-namespace:Deedy.Testing" + /// + /// + /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。 + /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 + /// 元素中: + /// + /// xmlns:MyNamespace="clr-namespace:Deedy.Testing;assembly=Deedy.Testing" + /// + /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用, + /// 并重新生成以避免编译错误: + /// + /// 在解决方案资源管理器中右击目标项目,然后依次单击 + /// “添加引用”->“项目”->[浏览查找并选择此项目] + /// + /// + /// 步骤 2) + /// 继续操作并在 XAML 文件中使用控件。 + /// + /// + /// + /// + public class ElegantWindow : Window + { + static ElegantWindow() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ElegantWindow), new FrameworkPropertyMetadata(typeof(ElegantWindow))); + } + public ElegantWindow() : base() + { + } + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + } + } +} diff --git a/DeedyDesigner/Deedy.Testing/ExMarkup.cs b/DeedyDesigner/Deedy.Testing/ExMarkup.cs new file mode 100644 index 0000000..9dccdca --- /dev/null +++ b/DeedyDesigner/Deedy.Testing/ExMarkup.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace Deedy +{ + public class ExMarkup : DependencyObject + { + + public static WindowDecorator GetWindowChrome(DependencyObject obj) + { + return (WindowDecorator)obj.GetValue(WindowChromeProperty); + } + + public static void SetWindowChrome(DependencyObject obj, WindowDecorator value) + { + obj.SetValue(WindowChromeProperty, value); + } + + // 用于自定义窗体的标题栏 + public static readonly DependencyProperty WindowChromeProperty = + DependencyProperty.RegisterAttached("WindowChrome", typeof(WindowDecorator), typeof(ExMarkup), new PropertyMetadata(null, (d, e) => + { + if (e.NewValue == null) + { + if (e.OldValue != null) ((WindowDecorator)e.OldValue).OnDetaching(); + } + else + { + if (d is Decorator) + { + Decorator header = (Decorator)d; + FrameworkElement? parent = header.Parent as FrameworkElement; + Window? target = parent as Window; + while (parent != null && target == null) + { + parent = parent.Parent as FrameworkElement; + target = parent as Window; + } + + if (target != null) ((WindowDecorator)e.NewValue).OnAttached(target, header); + else + { + if (!DesignerProperties.GetIsInDesignMode(d)) + throw new InvalidOperationException("窗体装饰器[WindowDecorator]对象在附加到作为标题栏容器的[Decorator]类型派生对象(例如[Border]对象)前,该容器必须已经挂接到一个窗体对象的视觉树上!"); + } + } + else throw new InvalidOperationException("窗体装饰器[WindowDecorator]对象只能附加到作为标题栏容器的[Decorator]类型派生对象(例如[Border]对象)上!"); + } + })); + + + + public static string GetTextBoxRegexMatch(DependencyObject obj) + { + return (string)obj.GetValue(TextBoxRegexMatchProperty); + } + + public static void SetTextBoxRegexMatch(DependencyObject obj, string value) + { + obj.SetValue(TextBoxRegexMatchProperty, value); + } + + // Using a DependencyProperty as the backing store for TextBoxRegexMatch. This enables animation, styling, binding, etc... + public static readonly DependencyProperty TextBoxRegexMatchProperty = + DependencyProperty.RegisterAttached("TextBoxRegexMatch", typeof(string), typeof(ExMarkup), new PropertyMetadata("", (d, e) => + { + if (d is TextBox textBox) + { + if (!string.IsNullOrEmpty(e.NewValue as string) && string.IsNullOrEmpty(e.OldValue as string)) + { + //加事件监听逻辑 + } + if (string.IsNullOrEmpty(e.NewValue as string) && !string.IsNullOrEmpty(e.OldValue as string)) + { + //取消事件监听逻辑 + } + } + })); + } +} diff --git a/DeedyDesigner/Deedy.Testing/Themes/Generic.xaml b/DeedyDesigner/Deedy.Testing/Themes/Generic.xaml new file mode 100644 index 0000000..56134d0 --- /dev/null +++ b/DeedyDesigner/Deedy.Testing/Themes/Generic.xaml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DeedyDesigner/Deedy.Testing/Waiting.xaml b/DeedyDesigner/Deedy.Testing/Waiting.xaml new file mode 100644 index 0000000..a4048d4 --- /dev/null +++ b/DeedyDesigner/Deedy.Testing/Waiting.xaml @@ -0,0 +1,46 @@ + + + + + + +