I looked for a solution to this problem for a long time without success.
I am porting some of my C# code to F# and I am struggling with a Dispatcher.Invoke for a WPF element. Since I am a total noob in F#, the only thing that I am sure of is that the problem is located between the chair and the keyboard.
Here is my C# code:
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();
}
));
}
The part I am struggling with is the new Action(delegate() ... ). The compiler did not like any of my attempts to translate it.
What would be the translation of this snippet in F#?
The Invoke
method has a couple of overloads, so if you have something not exactly right inside the action, you might have some weird errors because the type checker won't know which overload to call. I just tried this and it worked fine:
open System
open System.Windows.Controls
open System.Windows.Threading
let b = Button()
b.Dispatcher.Invoke(
DispatcherPriority.Normal,
Action(fun () ->
b.Content <- "foo"
)) |> ignore
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With