我找了很长时间没有成功解决这个问题的方法.
我正在将一些C#代码移植到F#,我正在为一个WPF元素的Dispatcher.Invoke而苦苦挣扎.由于我是F#中的总菜鸟,我唯一能确定的是问题出在椅子和键盘之间.
这是我的C#代码:
foreach (var k in ChartList.Keys)
{
ChartList[k].Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
ChartList[k].Width = area.Width / totalColsForm;
ChartList[k].Height = area.Height / totalRowsForm;
ChartList[k].Left = area.X + ChartList[k].Width * currentCol;
ChartList[k].Top = area.Y + ChartList[k].Height * currentRow;
ChartList[k].doShow();
}
));
}
Run Code Online (Sandbox Code Playgroud)
我正在努力的部分是新的Action(delegate()...).编译器不喜欢我试图翻译它.
F#中这个片段的翻译是什么?
该Invoke方法有两个重载,所以如果你在动作中有一些不完全正确的东西,你可能会有一些奇怪的错误,因为类型检查器不知道要调用哪个重载.我刚试过这个并且工作正常:
open System
open System.Windows.Controls
open System.Windows.Threading
let b = Button()
b.Dispatcher.Invoke(
DispatcherPriority.Normal,
Action(fun () ->
b.Content <- "foo"
)) |> ignore
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
553 次 |
| 最近记录: |