I am trying to dynamically add buttons into a wrappanel that is inside a scrollviewer. I am having no problems adding the buttons, but I am having troubles with the wrap panel bring the buttons up "too soon". The buttons will wrap up, but only half of the button is shown when they are sent up. If I further expand the window the button is shown as it is supposed to.
I would inline an image of what is happening but I don't have enough reputation. Here is the direct link to the image instead, showing my problem.
https://i.stack.imgur.com/tRI7c.png
Is there a way to tell the wrap panel to wait for the whole button to be able to fit before it wraps them up?
I've included the XAML code for the scroll viewer and wrap panel ( and the temporary button inside the wrap panel).
I've tried to play with the options in Visual Studio relating to the wrap panel, but I am at a loss. I know this is probably an easy fix.
<ScrollViewer x:Name="gameSroller" Margin="106,10,10,10">
<WrapPanel x:Name="gameWrapPanel" Height="900" Width="{Binding Path=ActualWidth,
RelativeSource={RelativeSource AncestorType=Window}}" HorizontalAlignment="Left" RenderTransformOrigin="0.5,0.5" ItemWidth="360">
<Button x:Name="button" Content="A Game" Width="350" Height="160" Padding="10,10,10,10" Margin="10">
<Button.Background>
<ImageBrush ImageSource="Resources/header.jpg"/>
</Button.Background>
</Button>
</WrapPanel>
</ScrollViewer>