Reputation: 15357
I have a WrapPanel inside a Window. In this case the controls inside the WrapPanel wrap when I manually resize the window.
However, the initial width is too much. I have put all controls in a horizontal wrap panel.
To make an initial width, I tried to set the Window to a width of 1000 (first try) and the wrappanel to 1000 (second try), but in this case the wrapping does not work anymore, only the 'border' (or padding) of the whole window is decreased or increased.
How can I change the width (and height) of the window in such a way that when I manually resize, the wrapping is taken into account.
Below a part of the XAML code:
Window x:Class="PcgTools.ListGenerator.ListGeneratorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding ListGenerator, Source={StaticResource LocStrings}}" ResizeMode="CanResizeWithGrip"
Icon="/PcgTools;component/Gui/pcgtools.ico" Loaded="Window_Loaded" Closed="Window_Closed"
ShowInTaskbar="True" WindowStartupLocation="CenterOwner" SizeToContent="WidthAndHeight">
<WrapPanel Name="wrapPanel" Margin="4" Orientation="Horizontal">
Upvotes: 1
Views: 2567
Reputation: 3519
This isn't directly related to the original question, but others might find it helpful, if like I did, they see this as one of the first search results in google, and no other results were helpful.
If you're encountering this in a Grid, you may have that Grid in a ScrollViewer with HorizontalScrollBarVisibility="Auto"
. You need to set that to Disabled
.
Upvotes: 1
Reputation: 15357
I found the answer after trying myself a lot of combinations, but I added it to help other people:
<Window x:Class="PcgTools.ListGenerator.ListGeneratorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Binding ListGenerator, Source={StaticResource LocStrings}}" ResizeMode="CanResizeWithGrip"
Icon="/PcgTools;component/Gui/pcgtools.ico" Loaded="Window_Loaded" Closed="Window_Closed"
ShowInTaskbar="True" WindowStartupLocation="CenterOwner"
Width="1000" SizeToContent="Height">
<WrapPanel Name="wrapPanel" Margin="4" Orientation="Horizontal">
The conclusion is:
Upvotes: 1