2016-05-24 12 views

答えて

0

このようなウィンドウのOnSizeChangedイベント、

を使用して行います。これを使用するときに、ウィンドウのSizeToContentプロパティでなければならないこと

//get Screen's Width, Height 
private double screenHeight = SystemParameters.FullPrimaryScreenHeight; 
private double screenWidth = SystemParameters.FullPrimaryScreenWidth; 
private void MultiToolWindow_OnSizeChanged(object sender, SizeChangedEventArgs e) 
{ 
    //when window RightBoundary over screen 
    if (this.Left + this.Width > screenWidth) 
     this.Width = screenWidth-this.Left; //shrink the width 
    //when window DownBoundary over screen 
    if (this.Top + this.Height > screenHeight) 
     this.Height = screenHeight-this.Top; //shrink the height 
} 

注意マニュアル、

ない場合、

あなたはこのようにそれを変更することができます。

public void SomeMethod(){ 

    //set to manual, this will invoke OnSizeChangedEvent at the same time but the shrink code won't work 
    this.SizeToContent = SizeToContent.Manual; 

    //this will invoke OnSizeChangedEvent and because now is manual the shrink code works 
    this.SizeToContent = SizeToContent.Manual; 


} 

は、ウィンドウの元SizeToContent状態があまりにも効果を取ることができWidthAndHeightあるとき、

初めてマニュアルに設定し、シュリンクコードが反映されませんを確認するために二回行います

と2回目の原因は手動のため、縮小コードが有効になります。