我试图让我的主窗口在启动时记住并恢复位置和大小。所以,我想我的窗口的启动位置绑定到我的视图模型一个属性如下:绑定窗口启动位置
<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