刚刚开始用WPF,需要设置程序初始化的大小以适应不同分辨率,在Window_Loaded事件中添加代码:
this.Left=0d;
this.Top=0d:
this.Height=SystemParameters.PrimaryScreenHeight;
this.Width=SystemParameters.PrimaryScreenWindth;
运行后的结果等于将WindowState设置为“Maximized”时的大小,但需求的不是这样,是能够显示出任务栏,于是将后两句改为:
this.Height=SystemParameters.FullPrimaryScreenHeight;
this.Width=SystemParameters.FullPrimaryScreenWindth;
这样,宽度是正常了,高度不正常,少了一截,于是又改成:
this.Height=SystemParameters.MaximizedPrimaryScreenHeight;
this.Width=SystemParameters.MaximizedPrimaryScreenWindth;
发现窗体比桌面大了一块,用代码得出了其大小,最后将代码改为下面这样才达到了目的,请高手指教一下原因是什么?
this.Height=SystemParameters.MaximizedPrimaryScreenHeight-8d;
this.Width=SystemParameters.MaximizedPrimaryScreenWindth-8d;