1
0
mirror of https://gitee.com/csharpui/CPF.git synced 2025-04-24 18:04:39 +08:00

button默认原生样式

This commit is contained in:
luxiaoqi 2023-11-23 16:36:19 +08:00
parent bc5e6be81e
commit a6fc04e737
4 changed files with 76 additions and 10 deletions

View File

@ -28,6 +28,7 @@ namespace CPF.Toolkit.Demo
Height = 400; Height = 400;
Background = null; Background = null;
this.DataContext = this.CommandContext = vm; this.DataContext = this.CommandContext = vm;
this.CanResize = true;
Children.Add(new WindowFrame(this, new WrapPanel Children.Add(new WindowFrame(this, new WrapPanel
{ {
@ -73,11 +74,15 @@ namespace CPF.Toolkit.Demo
new Button new Button
{ {
Content = "AsyncButton", Content = "AsyncButton",
Commands =
{
{ nameof(Button.AsyncClick),async (s,e) => await this.vm.AsyncClick() }
}
}.Assign(out var asyncButton), }.Assign(out var asyncButton),
} }
})); }));
asyncButton.AsyncClick += AsyncButton_AsyncClick; //asyncButton.AsyncClick += AsyncButton_AsyncClick;
} }
private async Task AsyncButton_AsyncClick(object sender, RoutedEventArgs e) private async Task AsyncButton_AsyncClick(object sender, RoutedEventArgs e)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Collections; using System.Collections;
using System.Threading.Tasks;
namespace CPF namespace CPF
{ {
@ -108,6 +109,17 @@ namespace CPF
list.Add(new Command { Action = action }); list.Add(new Command { Action = action });
} }
public void Add(string eventName, Func<CpfObject, object, Task> action)
{
List<Command> list;
if (!commands.TryGetValue(eventName, out list))
{
list = new List<Command>();
commands.Add(eventName, list);
}
list.Add(new Command { AsyncAction = action });
}
/// <summary> /// <summary>
/// KeyValuePair&lt;string, List&lt;Command&gt;&gt; /// KeyValuePair&lt;string, List&lt;Command&gt;&gt;
/// </summary> /// </summary>
@ -133,6 +145,6 @@ namespace CPF
public object[] Params; public object[] Params;
//public Relation Relation; //public Relation Relation;
public Action<CpfObject, object> Action; public Action<CpfObject, object> Action;
public Func<CpfObject, object, Task> AsyncAction;
} }
} }

View File

@ -16,8 +16,56 @@ namespace CPF.Controls
{ {
protected override void InitializeComponent() protected override void InitializeComponent()
{ {
this.Triggers.Add(nameof(IsMouseOver), Relation.Me, null, (nameof(Background), "190,230,253")); //this.MinWidth = 80;
this.Triggers.Add(nameof(IsPressed), Relation.Me, null, (nameof(Background), "186,209,226")); //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 Children.Add(new Border
{ {
Name = "contentPresenter", Name = "contentPresenter",
@ -33,12 +81,12 @@ namespace CPF.Controls
{ {
base.OnOverrideMetadata(overridePropertys); base.OnOverrideMetadata(overridePropertys);
overridePropertys.Override(nameof(BorderStroke), new UIPropertyMetadataAttribute(typeof(Stroke), "1", UIPropertyOptions.AffectsRender)); 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(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) //protected override void OnPropertyChanged(string propertyName, object oldValue, object newValue, PropertyMetadataAttribute propertyMetadata)
//{ //{

View File

@ -1809,7 +1809,7 @@ namespace CPF
{ {
foreach (var item in list) foreach (var item in list)
{ {
if (item.Action == null) if (item.AsyncAction == null)
{ {
var objs = new List<object>(); var objs = new List<object>();
object v = null; object v = null;
@ -1853,12 +1853,13 @@ namespace CPF
} }
} }
} }
obj.Invoke(item.MethodName, ps); await obj.AsyncInvoke(item.MethodName, ps);
} }
} }
else else
{ {
item.Action(this, eventArgs); //item.Action(this, eventArgs);
await item.AsyncAction(this, eventArgs);
} }
} }
} }