2012-10-18 115 views
2

我正在使用http://wpfmdi.codeplex.com/庫來處理我的WPF應用程序中的MDI。無法在窗口上設置自定義位置

我有一個Canvas其中包含一個子容器,所有的小窗口將被放置在這裏。我想要在x = 500,y = 500的位置打開窗戶。然而,用我現在的代碼,窗口總是在畫布的左上角打開。

下面我粘貼了我的XAML和在畫布上打開一個新窗口的代碼。

<Canvas Name="cnvsMain" Background="LightGray" AllowDrop="True" Drop="cnvsMain_Drop"> 
    <mdi:MdiContainer Name="mainContainer" Background="LightGray"> 
    </mdi:MdiContainer> 
</Canvas> 


      TableWindow tableWindow = new TableWindow(tableName); 
      listTableWindows.Add(tableWindow); 

      mainContainer.Children.Add(new MdiChild() 
      { 
       MaximizeBox = false, 
       MinimizeBox = false, 
       Resizable = true, 
       ShowIcon = false, 
       Title = "X", 
       Position = new Point(500,500), 
       Content = tableWindow.Content as UIElement //Opens new instance of my window class 
      }); 

任何想法?我也嘗試從我的窗口課程中設置位置,但無濟於事。

回答

2

只是spitballing在這裏,因爲我還沒有與特定的圖書館工作,但不是

mainContainer.Children.Add(new MdiChild() 
{ 
    MaximizeBox = false, 
    MinimizeBox = false, 
    Resizable = true, 
    ShowIcon = false, 
    Title = "X", 
    Position = new Point(500,500), 
    Content = tableWindow.Content as UIElement //Opens new instance of my window class 
}); 

你試過

var child = new MdiChild 
{ 
    MaximizeBox = false, 
    MinimizeBox = false, 
    Resizable = true, 
    ShowIcon = false, 
    Title = "X", 
    Position = new Point(0, 0), 
    Content = tableWindow.Content as UIElement //Opens new instance of my window class 
}; 

mainContainer.Children.Add(child); 
child.Position = new Point(500, 500); 
//  or 
//child.Margin = new Thickness(500, 500, 0, 0); 
+0

我已經試過逸岸,但無濟於事:/ –

+0

它實際上似乎已經工作,但由於某種原因,該窗口不會第一次出現 - 只有當代碼連續運行兩次時纔會出現窗口。 –

+0

@DotNET這是奇怪的,也許嘗試在初始化器中設置'Position = new Point(0,0)',並在將它添加到'Children'集合後重新設置它? – mlorbetske