ฉันกำลังพยายามทำให้หน้าต่างหลักของฉันจดจำและคืนค่าตำแหน่งและขนาดเมื่อเริ่มต้นระบบ ดังนั้นฉันจึงพยายามผูกตำแหน่งเริ่มต้นของหน้าต่างกับคุณสมบัติในโมเดลวิวของฉันดังต่อไปนี้:
<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 และ ข้อมูลเพิ่มเติม: ไม่สามารถตั้งค่า 'การเชื่อมโยง' บน 'WindowStartupLocation ' คุณสมบัติของประเภท 'MainWindow' สามารถตั้งค่า 'การเชื่อมโยง' ได้เฉพาะใน DependencyProperty ของ DependencyObject เท่านั้น
ฉันจะแก้ไขสิ่งนี้ได้อย่างไร?