2010-09-24 50 views
2

這是我的佈局。WPF定位取窗口的全高

<Window> 
<StackPanel Orientation="Vertical"> 
     <StackPanel HorizontalAlignment="Stretch" Height="30"> 
     </StackPanel> 
     <Canvas HorizontalAlignment="Center" Width="1020"> 
        <!--i want this to take the remaining full height of the screen--> 
        <Canvas x:Name="bottomInfoBar" Canvas.Bottom="0" Width="720" Height="39"> 
        <!--I want this at the very bottom of the screen--> 
        </Canvas> 
     </Canvas> 
</Window> 

我想在畫布上採取窗口的整個高度,使「bottomInfoBar」始終保持在用戶的屏幕的最底部。但是,如果我沒有爲畫布指定高度,那麼bottomInfoBar會出現在頂部。我如何實現這一目標?請幫忙。

回答

4

最簡單的方法:

<Window> 
    <DockPanel> 
     <Whatever x:Name="bottomInfoBar" DockPanel.Dock="Bottom"/> 

     <PrimaryContent/> 
    </DockPanel> 
</Window> 

根據你的問題,你真的應該閱讀有關WPF的layout system你寫的代碼,另一條線之前。如果你在繼續之前瞭解這一點,你將會爲自己節省一個痛苦的世界。

+0

你是對的,但我需要在畫布內有'bottomInfoBar'出於特定的原因。這是不可能的嗎? – 2010-09-24 10:08:21

+0

我想我的觀點是,如果首次獲得對佈局系統的更深入理解,您的具體原因可能會變得無關緊要。也就是說,沒有任何東西可以阻止你在停靠在底部的控件內託管'Canvas'。 – 2010-09-24 10:39:45

+0

我的具體原因是我需要爲主內容上的'bottomInfoBar'增加高度設置動畫效果。如果我把它放在主要內容之前並將其放置在底部,它就會動畫,但在主要內容之後。如果我把它放在主要內容之後,它根本不會動畫。對不起,我知道我對WPF定位很無能。 – 2010-09-24 11:06:17