2013-03-02 51 views
1

我在網格中有一個彈出控件,我希望它調整爲父級網格大小。正如你所看到的,父網格區域是綠色,彈出窗口是LightCyan顏色。 LightCyan區域應覆蓋整個綠地。我認爲我必須將ScrollViewer的寬度和高度設置爲父寬度和高度,但這不起作用。 請回復。謝謝如何將scrollviewer大小設置爲wpf中父級網格大小

我使用代碼在LinePopGrid中添加不同的東西。

<Grid Background="Green"> 
<Popup x:Name="LinePopUp" IsOpen="True" Placement="Relative" > 
     <ScrollViewer CanContentScroll="True" VerticalScrollBarVisibility="Auto"> 
      <Grid Background="LightCyan" x:Name="LinePopUpGrid" /> 
     </ScrollViewer> 
    </Popup> 
</Grid> 

Attached Picture

回答

5

您需要綁定彈出widthheight分別電網的ActualWidthActualHeight -

<Grid Background="Green"> 
     <Popup x:Name="LinePopUp" IsOpen="True" Placement="Relative" 
       Width="{Binding ActualWidth,RelativeSource={RelativeSource 
           Mode=FindAncestor, AncestorType=Grid}}"     
       Height="{Binding ActualHeight,RelativeSource={RelativeSource 
           Mode=FindAncestor, AncestorType=Grid}}"> 
      <ScrollViewer CanContentScroll="True" 
          VerticalScrollBarVisibility="Auto"> 
       <Grid Background="LightCyan" x:Name="LinePopUpGrid" /> 
      </ScrollViewer> 
     </Popup> 
</Grid> 
+0

太感謝你了,它的工作。我嘗試了類似的方式,但我使用寬度和高度而不是ActualHeight和ActualWidth,學到了一些新的東西。感謝那。 – SagarDabas 2013-03-02 12:42:55

+0

很高興幫助。要了解'Width'和'ActualWidth'之間的區別,請參閱此處的鏈接 - http://stackoverflow.com/questions/607827/what-is-the-difference-between-width-and-actualwidth-in-wpf – 2013-03-02 12:54:23

相關問題