Resolved Why don't these two gridsplitters do anything?

glasswizzard

Well-known member
Joined
Nov 22, 2019
Messages
126
Programming Experience
Beginner
Below is the XAML for the form that I recreated using just a grid, I added two gridsplitters to it (at the bottom) but they don't seem to actually do anything, I can't resize the grid with them. Is it because I've set specific sizes for the grid and it won't change from them?

C#:
<Window x:Class="FontViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:FontViewer"
        mc:Ignorable="d"
        Title="Font Viewer" Height="480" Width="600">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="2*"/>
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="0.8*"/>
            <RowDefinition Height="0.5*"/>
            <RowDefinition Height="0.7*"/>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="0.3*"/>
        </Grid.RowDefinitions>

        <Border CornerRadius="6"
                BorderThickness="1"
                BorderBrush="Gray"
                Background="LightGray"
                Padding="8"
                Margin="6"
                Grid.ColumnSpan="2">
            <TextBlock FontSize="14"
                       TextWrapping="Wrap">
                Select a font to view from the list below.
                You can change the text by typing in the region at the bottom.
            </TextBlock>
        </Border>

        <ListBox x:Name="FontList"
                 Grid.Row="1"
                 Grid.RowSpan="5"
                 HorizontalAlignment="Right"
                 ItemsSource="{x:Static Fonts.SystemFontFamilies}"
                 Width="190"
                 Margin="0 0 0 8">
        </ListBox>

        <TextBox x:Name="SampleText"
                 Grid.Row="5"
                 Grid.Column="1"
                 VerticalAlignment="Center"
                 Height="18"
                 MinLines="4"
                 Margin="0 0 6 0"
                 TextWrapping="Wrap"
                 ToolTip="Type here to change the preview text.">
            The quick brown fox jumps over the lazy dog.
        </TextBox>

        <TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
                   FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
                   FontSize="10"
                   TextWrapping="Wrap"
                   Margin="6"
                   Grid.Column="1"
                   Grid.Row="1"/>
        <TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
                   FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
                   FontSize="16"
                   TextWrapping="Wrap"
                   Margin="6"
                   Grid.Column="1"
                   Grid.Row="2"/>
        <TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
                   FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
                   FontSize="24"
                   TextWrapping="Wrap"
                   Margin="6"
                   Grid.Column="1"
                   Grid.Row="3"/>
        <TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
                   FontFamily="{Binding ElementName=FontList,Path=SelectedItem}"
                   FontSize="32"
                   TextWrapping="Wrap"
                   Grid.Column="1"
                   Grid.Row="3"
                   Margin="6,84,6,5.765" Grid.RowSpan="2"/>

        <GridSplitter Grid.Row="1"
                Grid.Column="0"
                Grid.RowSpan="6"
                Width="3"
                Background="Black"
                ResizeBehavior="PreviousAndNext"
                ResizeDirection="Columns" />

        <GridSplitter Grid.Row="5"
                Grid.Column="1"
                Height="3"
                Background="Black"
                HorizontalAlignment="Stretch"
                VerticalAlignment="Top"
                ResizeBehavior="PreviousAndNext"
                ResizeDirection="Rows" />
    </Grid>
</Window>
 
Last edited:
I've not yet tried your code, but personally, I would not have two splitters inside a single grid when they intersect or are perpendicular to each other. I would only keep them parallel to each other.

Personally, I would set up an outer grid that is split vertically. In one of the halves, I would another grid which is split horizontally.
 
Thanks for the advice Skydiver, it's not too important for this little bit of practice that I get it working I was just curious what may be going wrong but I now know it's something to do with the ResizeBehavior attribute. At this point that's all I need to know.
 
Back
Top Bottom