2013-03-02 50 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

相关问题