在我的小WPF應用程序(僅限F#)中,我想記住關閉後的窗口大小和位置。 This C# solution建議使用User.config的項目設置IDictinary。這看起來像我之後的簡單方法,但我沒有在我的F#項目中找到項目設置。它們是否適用於F#項目?F#爲WPF應用程序保留了一些用戶值
我試過,但它不工作:(保存()調用如C#示例不可用。)
let getSetting k def =
if Application.Current.Properties.Contains k
then Application.Current.Properties.Item k
else def
let window = System.Windows.Window()
// is box() the best wax to make floats into obj ?
window.Top <- getSetting "WindowTop" (box 0.0) |> unbox
window.Left <- getSetting "WindowLeft" (box 0.0) |> unbox
window.Height <- getSetting "WindowHeight" (box 800.0) |> unbox
window.Width <- getSetting "WindowWidth" (box 800.0) |> unbox
window.Closing.Add(fun _ ->
Application.Current.Properties.Add("WindowTop",window.Top)
Application.Current.Properties.Add("WindowHeight",window.Height)
Application.Current.Properties.Add("WindowLeft",window.Left)
Application.Current.Properties.Add("WindowWidth",window.Width)
//Application.Current.Properties.Save() // not available!
)
我知道我可以使用一個type provider但我想保持它如果可能的話,簡單且沒有依賴性。是否有內置的方式來保留F#WPF應用程序中的某些用戶值?
Properties.Settings.Default指這是從WPF應用程序的項目模板中包含的Properties-> Setting.settings文件生成的Settings類。 – mm8