diff --git a/CPF.Windows/UnmanagedMethods.cs b/CPF.Windows/UnmanagedMethods.cs index 07982fe..a087b14 100644 --- a/CPF.Windows/UnmanagedMethods.cs +++ b/CPF.Windows/UnmanagedMethods.cs @@ -1490,8 +1490,10 @@ BLENDFUNCTION blendFunction // alpha-blending function //[DllImport("shell32.dll", CharSet = CharSet.Auto)] //public static extern int DragQueryFile(HandleRef hDrop, int iFile, StringBuilder lpszFile, int cch); - [DllImport("dwmapi.dll", PreserveSig = false)] - public static extern bool DwmIsCompositionEnabled(); + //[DllImport("dwmapi.dll", PreserveSig = false)] + //public static extern bool DwmIsCompositionEnabled(); + [DllImport("dwmapi.dll", BestFitMapping = false)] + public static extern int DwmIsCompositionEnabled(out Int32 enabled); [DllImport("dwmapi.dll")] public static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind); diff --git a/CPF.Windows/WindowImpl.cs b/CPF.Windows/WindowImpl.cs index 1a02deb..eeb31fe 100644 --- a/CPF.Windows/WindowImpl.cs +++ b/CPF.Windows/WindowImpl.cs @@ -83,7 +83,7 @@ namespace CPF.Windows } posttime = Application.Elapsed; var v = System.Environment.OSVersion.Version; - if (v.Major >= 6 && DwmIsCompositionEnabled() && !Application.DesignMode) + if (v.Major >= 6 && DwmIsCompositionEnabled(out var e) == 0 && e == 1 && !Application.DesignMode) { } else @@ -92,7 +92,7 @@ namespace CPF.Windows } if ((v.Major == 6 && v.Minor < 2)) { - touchMsg = RegisterTouchWindow(handle, RegisterTouchFlags.TWF_NONE); + touchMsg = RegisterTouchWindow(handle, RegisterTouchFlags.TWF_NONE); } _className = "CPFWindow-" + Guid.NewGuid(); // 初始化窗口类结构 diff --git a/CPF/Binding.cs b/CPF/Binding.cs index d72013f..d217983 100644 --- a/CPF/Binding.cs +++ b/CPF/Binding.cs @@ -620,7 +620,7 @@ namespace CPF throw new Exception($"错误:{ex}"); } } - CpfObject SourceProperty = null; + //CpfObject SourceProperty = null; private void Target_PropertyChanged(object sender, PropertyChangedEventArgs e) { //重新绑定 diff --git a/CPF/Json/Reflection.cs b/CPF/Json/Reflection.cs index 0ddda5d..e5a9892 100644 --- a/CPF/Json/Reflection.cs +++ b/CPF/Json/Reflection.cs @@ -163,6 +163,10 @@ namespace CPF.Json { sd = new Dictionary(); var bf = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static; + if (type.Name == "Nullable`1") + { + type = type.GetGenericArguments()[0]; + } PropertyInfo[] pr = type.GetProperties(bf); foreach (PropertyInfo p in pr) { @@ -317,16 +321,26 @@ namespace CPF.Json } else // structs { - DynamicMethod dynMethod = new DynamicMethod("_", typeof(object), null); - ILGenerator ilGen = dynMethod.GetILGenerator(); - var lv = ilGen.DeclareLocal(objtype); - ilGen.Emit(OpCodes.Ldloca_S, lv); - ilGen.Emit(OpCodes.Initobj, objtype); - ilGen.Emit(OpCodes.Ldloc_0); - ilGen.Emit(OpCodes.Box, objtype); - ilGen.Emit(OpCodes.Ret); - c = (CreateObject)dynMethod.CreateDelegate(typeof(CreateObject)); - _constrcache.Add(objtype, c); + if (objtype.Name == "Nullable`1") + { + var sType = objtype.GetGenericArguments()[0]; + var create = objtype.GetConstructor(new Type[] { sType }); + c = () => create.Invoke(new object[] { null }); + _constrcache.Add(objtype, c); + } + else + { + DynamicMethod dynMethod = new DynamicMethod("_", typeof(object), null); + ILGenerator ilGen = dynMethod.GetILGenerator(); + var lv = ilGen.DeclareLocal(objtype); + ilGen.Emit(OpCodes.Ldloca_S, lv); + ilGen.Emit(OpCodes.Initobj, objtype); + ilGen.Emit(OpCodes.Ldloc_0); + ilGen.Emit(OpCodes.Box, objtype); + ilGen.Emit(OpCodes.Ret); + c = (CreateObject)dynMethod.CreateDelegate(typeof(CreateObject)); + _constrcache.Add(objtype, c); + } } return c(); } diff --git a/CPF/Platform/Application.cs b/CPF/Platform/Application.cs index 1fe0532..1c8deb1 100644 --- a/CPF/Platform/Application.cs +++ b/CPF/Platform/Application.cs @@ -228,6 +228,11 @@ namespace CPF.Platform get; set; } + /// + /// 某些平台下不能使用CPF的消息循环,需要将该属性改成false + /// + public static bool NeedRunLoop { get; set; } = true; + //#if NETSTANDARD // /// // /// 启用AOT功能,net5以及以上版本才能使用,其中包括,禁用弱引用事件功能,一般在Aot的release发布的时候设置。如果不用Aot,请勿设置,否则可能有内存泄露风险,而且会导致性能降低。 以及切换windows的com包装 diff --git a/CPF/Threading/DispatcherTimer.cs b/CPF/Threading/DispatcherTimer.cs index 15b234f..169aaba 100644 --- a/CPF/Threading/DispatcherTimer.cs +++ b/CPF/Threading/DispatcherTimer.cs @@ -46,7 +46,7 @@ namespace CPF.Threading if (timeThread == null) { timers = new List(); - tempTimers = new List(); + tempTimers = new List(); timeThread = new Thread(SetTime) { IsBackground = true, Name = "定时器线程" }; timeThread.Start(); } @@ -100,7 +100,7 @@ namespace CPF.Threading } if (tempTimers.Count > 0) { - if (CPF.Platform.Application.Main != null) + if ((CPF.Platform.Application.NeedRunLoop && CPF.Platform.Application.Main != null) || !CPF.Platform.Application.NeedRunLoop) { Dispatcher.MainThread.Invoke(() => {