diff --git a/CPF.Toolkit.Demo/MainView.cs b/CPF.Toolkit.Demo/MainView.cs index ac83c1b..36429c7 100644 --- a/CPF.Toolkit.Demo/MainView.cs +++ b/CPF.Toolkit.Demo/MainView.cs @@ -28,6 +28,7 @@ namespace CPF.Toolkit.Demo Height = 400; Background = null; this.DataContext = this.CommandContext = vm; + this.CanResize = true; Children.Add(new WindowFrame(this, new WrapPanel { @@ -73,11 +74,15 @@ namespace CPF.Toolkit.Demo new Button { Content = "AsyncButton", + Commands = + { + { nameof(Button.AsyncClick),async (s,e) => await this.vm.AsyncClick() } + } }.Assign(out var asyncButton), } })); - asyncButton.AsyncClick += AsyncButton_AsyncClick; + //asyncButton.AsyncClick += AsyncButton_AsyncClick; } private async Task AsyncButton_AsyncClick(object sender, RoutedEventArgs e) diff --git a/CPF/Commands.cs b/CPF/Commands.cs index e9320f0..c065630 100644 --- a/CPF/Commands.cs +++ b/CPF/Commands.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using System.Collections; +using System.Threading.Tasks; namespace CPF { @@ -108,6 +109,17 @@ namespace CPF list.Add(new Command { Action = action }); } + public void Add(string eventName, Func action) + { + List list; + if (!commands.TryGetValue(eventName, out list)) + { + list = new List(); + commands.Add(eventName, list); + } + list.Add(new Command { AsyncAction = action }); + } + /// /// KeyValuePair<string, List<Command>> /// @@ -133,6 +145,6 @@ namespace CPF public object[] Params; //public Relation Relation; public Action Action; + public Func AsyncAction; } - } diff --git a/CPF/Controls/Button.cs b/CPF/Controls/Button.cs index cb1dc66..4f02e28 100644 --- a/CPF/Controls/Button.cs +++ b/CPF/Controls/Button.cs @@ -16,8 +16,56 @@ namespace CPF.Controls { protected override void InitializeComponent() { - this.Triggers.Add(nameof(IsMouseOver), Relation.Me, null, (nameof(Background), "190,230,253")); - this.Triggers.Add(nameof(IsPressed), Relation.Me, null, (nameof(Background), "186,209,226")); + //this.MinWidth = 80; + //this.MinHeight = 35; + //this.MarginRight = 1; + this.Triggers.Add(new Trigger + { + Property = nameof(IsMouseOver), + TargetRelation = Relation.Me, + PropertyConditions = x => Convert.ToBoolean(x), + Setters = + { + { nameof(Background),"#E5F1FB" }, + { nameof(BorderFill),"#0078D7" }, + { nameof(Foreground),"black" }, + } + }); + this.Triggers.Add(new Trigger + { + Property = nameof(IsPressed), + TargetRelation = Relation.Me, + PropertyConditions = x => Convert.ToBoolean(x), + Setters = + { + { nameof(Background),"204,228,247" }, + { nameof(BorderFill),"0,84,153" }, + } + }); + this.Triggers.Add(new Trigger + { + Property = nameof(IsFocused), + TargetRelation = Relation.Me, + PropertyConditions = x => Convert.ToBoolean(x), + Setters = + { + { nameof(Background),"204,228,247" }, + { nameof(BorderFill),"0,120,215" }, + { nameof(BorderStroke),"2" }, + } + }); + this.triggers.Add(new Trigger + { + Property = nameof(IsEnabled), + TargetRelation = Relation.Me, + PropertyConditions = x => !Convert.ToBoolean(x), + Setters = + { + { nameof(Background),"204,204,204" }, + { nameof(BorderFill),"191,191,191" }, + { nameof(Foreground),"131,131,131" }, + } + }); Children.Add(new Border { Name = "contentPresenter", @@ -33,12 +81,12 @@ namespace CPF.Controls { base.OnOverrideMetadata(overridePropertys); overridePropertys.Override(nameof(BorderStroke), new UIPropertyMetadataAttribute(typeof(Stroke), "1", UIPropertyOptions.AffectsRender)); - overridePropertys.Override(nameof(BorderFill), new UIPropertyMetadataAttribute((ViewFill)"#101010", UIPropertyOptions.AffectsRender)); + overridePropertys.Override(nameof(BorderFill), new UIPropertyMetadataAttribute((ViewFill)"#ADADAD", UIPropertyOptions.AffectsRender)); overridePropertys.Override(nameof(IsAntiAlias), new UIPropertyMetadataAttribute(false, UIPropertyOptions.AffectsRender)); - overridePropertys.Override(nameof(Background), new UIPropertyMetadataAttribute((ViewFill)"221,221,221", UIPropertyOptions.AffectsRender)); + overridePropertys.Override(nameof(Background), new UIPropertyMetadataAttribute((ViewFill)"#E1E1E1", UIPropertyOptions.AffectsRender)); } - + //protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata) //{ diff --git a/CPF/CpfObject.cs b/CPF/CpfObject.cs index 94729ef..b63fc91 100644 --- a/CPF/CpfObject.cs +++ b/CPF/CpfObject.cs @@ -1809,7 +1809,7 @@ namespace CPF { foreach (var item in list) { - if (item.Action == null) + if (item.AsyncAction == null) { var objs = new List(); object v = null; @@ -1853,12 +1853,13 @@ namespace CPF } } } - obj.Invoke(item.MethodName, ps); + await obj.AsyncInvoke(item.MethodName, ps); } } else { - item.Action(this, eventArgs); + //item.Action(this, eventArgs); + await item.AsyncAction(this, eventArgs); } } }