简体   繁体   English

如何在wpf中将scrollviewer大小设置为父级的网格大小

[英]How to set the scrollviewer size to the parent's grid size in wpf

I have a popup control in a grid and I want it to resize to the parent grid size. 我在网格中有一个弹出控件,并且希望将其调整为父网格大小。 As you can see the parent grid area is in Green color and the popup is in LightCyan color. 如您所见,父网格区域为绿色,弹出窗口为LightCyan颜色。 The area in the LightCyan should cover the whole green area. LightCyan中的区域应覆盖整个绿色区域。 And I think I have to set the Scrollviewer width and height to the parent's width and height but that didn't work. 而且我认为我必须将Scrollviewer的宽度和高度设置为父级的宽度和高度,但这没有用。 Please reply. 请回复。 Thanks 谢谢

I am adding different stuff in the LinePopGrid using code. 我正在使用代码在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>

附图片

You need to bind PopUp width and height to Grid's ActualWidth and ActualHeight respectively - 您需要将PopUp的widthheight分别绑定到Grid的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM