Skip to content

Commit

Permalink
fix #64
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatao Li committed Sep 18, 2019
1 parent af99aed commit 173164c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions Views/MainWindow.xaml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ type MainWindow() as this =
this.Bind(XProp, Binding("X", BindingMode.TwoWay))
this.Bind(YProp, Binding("Y", BindingMode.TwoWay))

this.PositionChanged.Subscribe (fun p ->
this.SetValue(XProp, p.Point.X)
this.SetValue(YProp, p.Point.Y))

States.Register.Notify "DrawFPS" (fun [| Bool(v) |] ->
trace "Model" "DrawFPS: %A" v
trace "mainwindow" "DrawFPS: %A" v
this.Renderer.DrawFps <- v)

this.AddHandler(DragDrop.DropEvent, (fun _ (e: DragEventArgs) ->
Expand All @@ -51,13 +47,30 @@ type MainWindow() as this =
this.AddHandler(DragDrop.DragOverEvent, (fun _ (e:DragEventArgs) ->
e.DragEffects <- DragDropEffects.Move ||| DragDropEffects.Link ||| DragDropEffects.Copy
))

]
AvaloniaXamlLoader.Load this


override this.OnDataContextChanged _ =
let ctx = this.DataContext :?> MainWindowViewModel
let pos = PixelPoint(int ctx.X, int ctx.Y)
let mutable firstPoschange = true
let mutable deltaX = 0
let mutable deltaY = 0

trace "mainwindow" "set position: %d, %d" pos.X pos.Y
this.Position <- pos
this.WindowState <- ctx.WindowState
this.Watch [
this.PositionChanged.Subscribe (fun p ->
if firstPoschange then
firstPoschange <- false
deltaX <- p.Point.X - pos.X
deltaY <- p.Point.Y - pos.Y
trace "mainwindow" "first PositionChanged event: %d, %d (delta=%d, %d)" p.Point.X p.Point.Y deltaX deltaY
else
this.SetValue(XProp, p.Point.X - deltaX)
this.SetValue(YProp, p.Point.Y - deltaY)
)
]

0 comments on commit 173164c

Please sign in to comment.