3

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

Silver Solver
  • 2,310
  • 1
  • 13
  • 19
SagarDabas
  • 89
  • 1
  • 2
  • 9

1 Answers1

7

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>
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
  • Thank you so much, it worked. I tried in the similar way but I used Width and Height instead of ActualHeight and ActualWidth, learnt something new. Thanks for that. – SagarDabas Mar 02 '13 at 12:42
  • Glad to help. To know the difference between `Width` and `ActualWidth` refer to this link here - http://stackoverflow.com/questions/607827/what-is-the-difference-between-width-and-actualwidth-in-wpf – Rohit Vats Mar 02 '13 at 12:54
  • This won't work. ActualWidth and ActualHeight are not notified properties, so when they change the binding will not update. See note in https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.frameworkelement.actualwidth – sjb-sjb Jul 28 '18 at 21:42