0

I try to define the width of a WPF <Frame> control to the size of its parant (<StackPanel> which fills the entire window width). For any reason the Frame element just takes the width of its child and not of its parent. I have googled for many "parent width" solutions (other container controls) but none of the worked with a Frame. Actually the HorizontalAlignment="Stretch" setting suppose to make it possible, but it doesn't work.

My code:

<StackPanel Orientation="Horizontal" Background="BlueViolet" HorizontalAlignment="Stretch">
    <Frame Background="Yellow" HorizontalAlignment="Stretch" />  
</StackPanel>

Any idea how to set the width of a Frame UI control to its parent?

Update Answer:

It seems that the width setting of a Frame does not to work in combination with a StackPanel as parent. When I use a Grid container instead, then the Frame width adjusts as expected to the cell width defined in the Grid.

eglobetrotter
  • 718
  • 4
  • 10
  • 25
  • 2
    Use a different Panel, e.g. a Grid or DockPanel. – Clemens Jan 06 '20 at 11:30
  • @Clemens: I tried with DockPanel before, but got same result. I just figured out thet it's due to StackPanel. When I use Frame directly then it expands to the width of its parent which is a Grid cell now. – eglobetrotter Jan 06 '20 at 11:40
  • StackPanel is the wrong container for a child element that should expand in both directions. No idea what exactly you tried with a DockPanel, but you should replace the StackPanel with a Grid or DockPanel. – Clemens Jan 06 '20 at 11:44

0 Answers0