mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-04-05 17:37:51 +08:00
button默认原生样式
This commit is contained in:
parent
bc5e6be81e
commit
a6fc04e737
@ -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)
|
||||
|
@ -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<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>
|
||||
/// KeyValuePair<string, List<Command>>
|
||||
/// </summary>
|
||||
@ -133,6 +145,6 @@ namespace CPF
|
||||
public object[] Params;
|
||||
//public Relation Relation;
|
||||
public Action<CpfObject, object> Action;
|
||||
public Func<CpfObject, object, Task> AsyncAction;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
//{
|
||||
|
@ -1809,7 +1809,7 @@ namespace CPF
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (item.Action == null)
|
||||
if (item.AsyncAction == null)
|
||||
{
|
||||
var objs = new List<object>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user