ListBox control not resizing when window is maximized

I am still new to VS, C# and XAML. I have this code below

<Window x:Class="KANASoft___Xplora.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStartupLocation="CenterScreen" Icon="folder.gif" ResizeMode="CanResizeWithGrip"
        Title="KANASoft - Xplora" Height="700" Width="535" Background="Black" Name="mainWindow">
    <Grid Height="{Binding ElementName=mainWindow, Path=Height}" Width="{Binding ElementName=mainWindow, Path=Width}">
        <ListBox Background="Black" Name="LBHeader" BorderBrush="Aqua" ScrollViewer.HorizontalScrollBarVisibility="Disabled" BorderThickness="0 0 0 1" Height="80" VerticalAlignment="Top">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Horizontal" Width="{Binding ElementName=mainWindow, Path=Width}"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</Window>

I want my <ListBox Name="LBHeader"> to resize according to the window's width when the window is resized and it works fine when I resize the window by dragging the window edges. But the problem is that when I maximize the window, the <ListBox Name="LBHeader"> doesn't resize with the window.

Please I need help on this.

#c-sharp #xaml

5 Likes2.65 GEEK