- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
给定以下方法:
public static void ExecuteAsync( this EventHandler eH, object sender, EventArgs eA ) {
eH.GetInvocationList( ).Cast<EventHandler>( ).ToList( ).ForEach( e => {
e.BeginInvoke( sender, eA, IAR =>
( ( IAR as AsyncResult ).AsyncDelegate as EventHandler ).EndInvoke( IAR ), null );
} );
}
我注意到 e
有一个属性 Target。
当我进一步研究它时,我发现我可以检查 e.Target 是 System.Windows.Controls.Control
还是 e.Target 是 System.Windows.Forms.Control
.
这太棒了,因为在使用这个扩展的情况下,为了方便(而且我很懒),我希望能够判断委托(delegate)目标是否需要调用委托(delegate)(在这种情况下WinForms:Control.Invoke(foo)
;对于 WPF:Control.Dispatcher.Invoke(foo)
).
我不需要知道如何将对象转换为它的实际类型(我可以没有它):我只需要知道如何转换对象以便我可以访问 InvokeRequired
属性和 Invoke
方法(在 WinForms 控件的情况下),或 Dispatcher
属性(用于访问 Dispatcher.CheckAccess( )
函数和 Dispatcher.Invoke( )
方法)。
这可能吗?我该怎么做呢? (我试过将 e.Target 转换为 System.Windows.Control.Control
但结果没有 Dispatcher
属性)。
根据对转换代码(和导入/引用)的请求:
判断是否为WPF控件:
( if e.Target is System.Windows.Controls.Control ){ //Fully Qualified
( e.Target as System.Windows.Controls.Control)./*...*/;
}
判断是否为WinForms控件:
( if e.Target is System.Windows.Forms.Control ){ //Fully Qualified
( e.Target as System.Windows.Forms.Control )./*...*/;
}
该项目引用了几个库:
Microsoft.CSharp
MySql.Data
PresentationFramework
System
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Drawing
System.Management
System.Windows.Forms
System.Xml
System.Xml.Linq
最佳答案
这不适合你。这不是最优雅的方式,但可以检查目标是 WPF 还是 WinForms 控件:
if (e.Target is System.Windows.Controls.Control)
{
var wpfTarget = ((System.Windows.Controls.Control)e.Target);
if (wpfTarget.Dispatcher.CheckAccess()) // check if on dispatcher thread
{
wpfTarget.Dispatcher.Invoke(/*...*/);
}
}
else if (e.Target is System.Windows.Forms.Control)
{
var formsTarget = (System.Windows.Forms.Control)e.Target;
if (formsTarget.InvokeRequired)
{
formsTarget.Invoke(/*...*/);
}
}
在 VisualStudio 中,我对 wpfTarget
上的 Dispatcher
提供了 Intelisense 支持:
编辑
在我包含的引用文献下方
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
其中只有四个在使用:
using System;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Windows;
关于c# - 如何调用 Delegate.Target 的 .Invoke 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34192689/
我有一个 div,我希望使用 css 显示为 :target。到目前为止,这工作正常。我的问题是:我希望它淡入淡出。 我的代码: Content #stuff { opacity:0;
我想找到在Rust构建中使用的libc.so文件,以便我可以使用--version进行查询。 (一些libcs通过C宏公开其版本信息,因此,它们的另一种选择是在构建脚本中使用cc条板箱。但其他诸如
我仍然不明白为什么 Makefile 中的“虚假”规则将“.PHONY”作为其目标。作为先决条件,这会更合乎逻辑。 我需要详细说明这一点吗?如果A依赖于B并且B是假的,那么A也是假的。因此,与 .PH
在 Fortran 语言中,向具有 TARGET 属性的虚拟参数的过程提供不具有 TARGET 属性的参数应该会导致无效代码。但是,当使用 gfortran (5.1.0) 或 ifort (14.0
如果有人发布过相同的问题,请原谅我,我找不到类似问题的答案。 当我单击带有 #dotNetComponents url 的按钮时,它会将我带到带有 dotNetComponents ID 的 div,
我想用 :target 伪类更改我的 html 中元素的样式。我的标记(第一个是按钮,第二个是目标元素): Call to action target CSS: #btn01:target { b
下面提到的示例代码是 Keith Wood 的 jQuery Countdown 插件的一部分。有人能解释一下吗 _attachCountdown: function(target, options)
我是 React 的新手。这绝对让我感到困惑。我可以使用 event.target 访问 HTML 元素,它显示的值等于某个数字,但每次我使用 event.target.value 时,我都会得到 u
这个问题是关于交叉编译的。 使用 swift 编译器的 -target 或 -target-cpu 选项可以使用哪些不同的目标?我在哪里可以找到概述? 它只能用于创建 iOS/watchOS 应用程序
在CKEditor 5中,我没有在链接对话框中看到目标属性的字段。 如何添加这样的字段?或将target = _blank设置为默认值。 谢谢 最佳答案 从Link Plugin的11.1.0版本开始
问题:FAKE 中是否有一个命令可以打印构建脚本中所有定义的目标? 我想以这样的方式设置我的 FAKE 构建:当我不指定目标时,它会打印构建脚本中所有可用目标的列表。 例如: > build.cmd
尝试使用 Visual Studio 2013 Update 3 创建一个新的 Cordova“空白应用程序”。 我看到了模板,但是当尝试打开空白应用程序时,我得到: The imported pro
http://download.oracle.com/javase/6/docs/api/java/lang/annotation/Target.html 此元注释指示声明的类型仅用作复杂注释类型声明
使用CocoaPods,有什么区别 target :TargetName do # Some pods... end 和 target "TargetName" do #
我正在尝试仅使用 CSS 制作一个简单的移动菜单切换。通过显示和隐藏两个按钮,这些按钮具有指向显示或隐藏导航菜单的类的不同链接。 是本教程的编辑link ,但现在我想让关闭和打开按钮位于单独的 div
以下是包含简单日志文件目标的简单 nlog 配置。我的问题是如何为 Nlog.Targets.Redis 添加目标? 最佳答案 以下是 NLog.Targets.Redis 的正确配置。如果
我想知道您是否可以将一个单元测试包链接到多个目标。因此,可以使用一个测试包测试所有应用程序目标。 我在所有应用程序目标之间有一些共享代码,但也有一些基于正在运行的应用程序目标的特定计算。 目前,如果我
我在 VSTS 中使用部署组将我的应用程序部署到本地测试 Web 服务器。 它已经运行良好很长时间了,但是在大约 6 周没有使用它之后,我现在遇到了这个错误,我想修复它; 最佳答案 您的代理未运行或无
使用 CMake 构建开源项目时(在我的例子中,它是柠檬图库),当我尝试通过 -DBUILD_SHARED_LIBS=1 构建共享库时出现此错误。 : TARGETS given no LIBRARY
尝试安装 ionic,添加 android 平台时出现以下错误 Error: Please install Android target "android-19". Hint: Run "androi
我是一名优秀的程序员,十分优秀!