Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

xaml

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. The area in the LightCyan should cover the whole green area. And I think I have to set the Scrollviewer width and height to the parent's width and height but that didn't work. Please reply. Thanks

I am adding different stuff in the LinePopGrid using code.

<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

like image 837
SagarDabas Avatar asked Oct 14 '25 04:10

SagarDabas


1 Answers

You need to bind PopUp width and height to Grid's ActualWidth and ActualHeight respectively -

<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>
like image 103
Rohit Vats Avatar answered Oct 16 '25 18:10

Rohit Vats



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!