我試圖讓我的主窗口在啓動時記住並恢復位置和大小。所以,我想我的窗口的啓動位置綁定到我的視圖模型一個屬性如下:綁定窗口啓動位置
<Window x:Class="MyApp.Views.MainWindow"
...
Width="{Binding Width}"
Height="{Binding Height}"
WindowStartupLocation="{Binding WindowStartupLocation}"
WindowState="{Binding WindowState}"
MinHeight="600"
MinWidth="800"
Closing="OnWindowClosing"
Closed="OnWindowClosed"
ContentRendered="OnMainWindowReady"
...>
我的視圖模型:
...
// Default settings
WindowState = (WindowState)FormWindowState.Normal;
this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
Width = 800;
Height = 600;
// check if the saved bounds are nonzero and is visible on any screen
if (Properties.Settings.Default.WindowStartupLocation != Rectangle.Empty &&
IsVisibleOnAnyScreen(Properties.Settings.Default.WindowStartupLocation))
{
this.WindowStartupLocation = WindowStartupLocation.Manual;
this.WindowState = (WindowState)Properties.Settings.Default.WindowState;
Height = Properties.Settings.Default.WindowStartupLocation.Size.Height;
Width = Properties.Settings.Default.WindowStartupLocation.Size.Width;
Left = Properties.Settings.Default.WindowStartupLocation.Left;
Top = Properties.Settings.Default.WindowStartupLocation.Top;
}
...
當我運行該應用程序,我得到一個System.Windows.Markup .XamlParseException和附加信息:無法在「MainWindow」類型的「WindowStartupLocation」屬性上設置「綁定」。 '綁定'只能在DependencyObject的DependencyProperty上設置。
我應該如何糾正?
嗯這個問題似乎更復雜,然後我雖然。但謝謝生病給我一個嘗試:) – Lynct 2014-12-18 22:49:44