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

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

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