2011-02-07 6 views
0

私はコントロールをホストするwpfウィンドウを持っています。 ウィンドウの高さと幅はSizeToControlに設定されています。wpfでレンダリングする前にコントロールの実際の幅を取得できない問題

ここでは、親ウィンドウの位置を基準にしてこのウィンドウを配置する必要があります(基本的には右上の位置)。

(だから私の窓Top = ParentWindow.Top, and Left = ParentWindow.Left + ParentWindow.ActualWidth - control.ActualWidth私のウィンドウが親ウィンドウの内側が、その右の角に位置するように)

だから私は、ウィンドウの上部と左を設定する必要があります。これを行うには、私はそれの内側にホストされているコントロールの実際の幅を必要とする....が、私は実際に、

Window.Show(control,parent)

は、この問題を回避する方法はあります一度私はこれだけを得ることができます?どのように実際に表示される前にコントロールのレンダリングされた実際の幅を取得するのですか?

ありがとうございます!

答えて

1

この方法を試しましたか?

public partial class ShellWindow : Window 
    { 
     public ShellWindow(IShellPresentationModel model) 
     { 
      InitializeComponent(); 
      this.Loaded += ShellWindow_Loaded; 
     } 

     void ShellWindow_Loaded(object sender, RoutedEventArgs e) 
     { 
      var innerWindow = new InnerWindow(); 
      innerWindow.Owner = this; 
      innerWindow.Loaded += InnerWindow_Loaded; 
      innerWindow.Show(); 
     } 

     void InnerWindow_Loaded(object sender, RoutedEventArgs e) 
     { 
      var w = (InnerWindow)sender; 
      w.Owner = this; 
      w.Top = this.Top; 
      w.Left = this.Left + this.ActualWidth - w.ActualWidth; 
     } 
} 
関連する問題