Commit 1da75c4d authored by 潘栩锋's avatar 潘栩锋 🚴

优化 虚拟键盘 全键盘 把 ,.独立,不需要按123切换。

优化 虚拟键盘 全键盘 123 按钮,变成static,会保持上次状态
优化 Reflect_SeviceClient 初始化时检查event是否存在,引发异常
parent bc6a413f
......@@ -8,7 +8,7 @@
WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
Height="400" Width="800" Background="#525a65" Loaded="Window_Loaded">
Height="350" Width="650" Background="#525a65" Loaded="Window_Loaded">
<Window.Resources>
<local:FullKeyboardViewModel x:Key="viewModel"/>
</Window.Resources>
......@@ -219,6 +219,7 @@
<ColumnDefinition Width="100*"/>
<ColumnDefinition Width="300*"/>
<ColumnDefinition Width="100*"/>
<ColumnDefinition Width="100*"/>
<ColumnDefinition Width="250*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Name="button_close" Style="{StaticResource ButtonStyle_opt}" Click="button_close_Click">
......@@ -229,9 +230,12 @@
</Button>
<Button Grid.Column="2" Name="button_space" Style="{StaticResource ButtonStyle_abc}" Click="button_space_Click" />
<Button Grid.Column="3" Name="button_dot" Style="{StaticResource ButtonStyle_abc}" Click="button_Click">
<TextBlock Text="{Binding KeyDot}" Style="{StaticResource TextBlockStyle_abc}" />
<TextBlock Text="." Style="{StaticResource TextBlockStyle_abc}" />
</Button>
<Button Grid.Column="4" Style="{StaticResource ButtonStyle_abc}" Click="button_Click">
<TextBlock Text="," Style="{StaticResource TextBlockStyle_abc}" />
</Button>
<Button Grid.Column="4" Name="button_enter" Style="{StaticResource ButtonStyle_opt}" Click="button_enter_Click">
<Button Grid.Column="5" Name="button_enter" Style="{StaticResource ButtonStyle_opt}" Click="button_enter_Click">
<iconPacks:Material Kind="KeyboardReturn" />
</Button>
</Grid>
......
......@@ -238,12 +238,12 @@ namespace FLY.ControlLibrary.UI.OSK
public string KeyDot { get; set; }
static bool is123 = false;
public FullKeyboardViewModel()
{
IsCapsLock = false;
Is123 = false;
Is123 = is123;
UpdateKey();
......@@ -252,11 +252,12 @@ namespace FLY.ControlLibrary.UI.OSK
void FullKeyPad_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Is123")
if (e.PropertyName == nameof(Is123))
{
is123 = Is123;
UpdateKey();
}
if (e.PropertyName == "IsCapsLock")
if (e.PropertyName == nameof(IsCapsLock))
{
UpdateKey();
}
......
......@@ -38,6 +38,7 @@ namespace FObjBase.Reflect
public string name;
public string triggerName;
public Type retType;
public MethodInfo methodInfo;
}
class AnyCall
{
......@@ -125,13 +126,13 @@ namespace FObjBase.Reflect
void InitEventPush()
{
var interfaceTypes = new List<Type>();
var interfaceTypes = new List<Type>();//获取全部接口
interfaceTypes.Add(InterfaceType);
interfaceTypes.AddRange(InterfaceType.GetInterfaces());
var eventInfos = new List<EventInfo>();
var eventInfos = new List<EventInfo>();//获取全部接口的全部event
foreach (var ifaceType in interfaceTypes)
{
eventInfos.AddRange(ifaceType.GetEvents());
......@@ -139,14 +140,15 @@ namespace FObjBase.Reflect
foreach (var eventInfo in eventInfos)
{
var pushAttribute = eventInfo.GetCustomAttribute<PushAttribute>();
var pushAttribute = eventInfo.GetCustomAttribute<PushAttribute>();//有[Push]特性的event
if (pushAttribute == null)
continue;
if (anyEvents.Any(ae => ae.name == eventInfo.Name))
continue;//已经添加了
string triggerName;
if (string.IsNullOrEmpty(pushAttribute.TriggerName))
if (string.IsNullOrEmpty(pushAttribute.TriggerName))//没有定义触发方法的名字,使用默认组合
{
triggerName = PushAttribute.DefaultTriggerNameHeader + eventInfo.Name;
}
......@@ -154,11 +156,25 @@ namespace FObjBase.Reflect
{
triggerName = pushAttribute.TriggerName;
}
//测试触发方法是否存在,没有抛出异常
var methodInfo = GetType().GetMethod(triggerName);
if (methodInfo == null)
{
throw new Exception($"客户端 {GetType()} 忘记写 {triggerName}");
}
var anyEvent = new AnyEvent()
{
name = eventInfo.Name,
triggerName = triggerName,
retType = pushAttribute.EventArgsType
retType = pushAttribute.EventArgsType,
methodInfo = methodInfo
};
anyEvents.Add(anyEvent);
......@@ -328,16 +344,14 @@ namespace FObjBase.Reflect
var anyEvent = anyEvents.Find(ae => ae.name == rData.name);
if (anyEvent == null)
return;//异常!!!
return;//异常!!!, 在构造客户端时,已经检查完了,现在服务器乱发东西过来。
//触发事件!!!
var methodInfo = GetType().GetMethod(anyEvent.triggerName);
if (methodInfo == null)
{
throw new Exception($"客户端 {GetType()} 忘记写 {anyEvent.triggerName}");
}
var methodInfo = anyEvent.methodInfo;
//事件的数据转为 EventArgs 类型
var obj = rData.data.ToObject(anyEvent.retType);
//出错,就提示,肯定是客户端忘记写 "Trigger_XXXX"
methodInfo.Invoke(this, new object[] { obj });
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment