Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have two suggestions:</p> <p>1) if you are using f# interactive check you have installed a WFP event loop. F# interactive sets up a winforms eventloop by default, there is some compatibility between the winforms and WFP event loops, but not everything works to correctly. To install the event loop use the following script:</p> <pre><code>#light // When running inside fsi, this will install a WPF event loop #if INTERACTIVE #I "c:/Program Files/Reference Assemblies/Microsoft/Framework/v3.0";; #I "C:/WINDOWS/Microsoft.NET/Framework/v3.0/WPF/";; #r "presentationcore.dll";; #r "presentationframework.dll";; #r "WindowsBase.dll";; module WPFEventLoop = open System open System.Windows open System.Windows.Threading open Microsoft.FSharp.Compiler.Interactive open Microsoft.FSharp.Compiler.Interactive.Settings type RunDelegate&lt;'b&gt; = delegate of unit -&gt; 'b let Create() = let app = try // Ensure the current application exists. This may fail, if it already does. let app = new Application() in // Create a dummy window to act as the main window for the application. // Because we're in FSI we never want to clean this up. new Window() |&gt; ignore; app with :? InvalidOperationException -&gt; Application.Current let disp = app.Dispatcher let restart = ref false { new IEventLoop with member x.Run() = app.Run() |&gt; ignore !restart member x.Invoke(f) = try disp.Invoke(DispatcherPriority.Send,new RunDelegate&lt;_&gt;(fun () -&gt; box(f ()))) |&gt; unbox with e -&gt; eprintf "\n\n ERROR: %O\n" e; rethrow() member x.ScheduleRestart() = () //restart := true; //app.Shutdown() } let Install() = fsi.EventLoop &lt;- Create() WPFEventLoop.Install();; #endif </code></pre> <p>2) I haven't tested this too well, but I think using an animation story board will give smother more consistent results, rather than using a timer. I think this would look something like (changing the width property haven't worked out how to change the position):</p> <pre><code>#light open System open System.Windows open System.Windows.Controls open System.Windows.Shapes open System.Windows.Media open System.Windows.Media.Animation let rect = new Rectangle(Fill = new SolidColorBrush(Colors.Red), Height = 20., Width = 20., Name = "myRectangle") let canvas = let c = new Canvas() c.Children.Add(rect) |&gt; ignore c NameScope.SetNameScope(canvas, new NameScope()); canvas.RegisterName(rect.Name, rect) let window = new Window(Content = canvas) let nfloat f = new Nullable&lt;float&gt;(f) let myDoubleAnimation = new DoubleAnimation(From = nfloat 20.0, To = nfloat 50.0, Duration = new Duration(TimeSpan.FromSeconds(5.)), RepeatBehavior = RepeatBehavior.Forever) let myStoryboard = let sb = new Storyboard() sb.Children.Add(myDoubleAnimation) sb Storyboard.SetTargetName(myDoubleAnimation, rect.Name); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Rectangle.WidthProperty)) rect.Loaded.Add(fun _ -&gt; myStoryboard.Begin canvas) let main() = let app = new Application() app.Run window |&gt; ignore [&lt;STAThread&gt;] do main() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload