Answered Grid Splitter Not working properly

  • 05 April 2008 3:11
     
     

    I have added two grid splitters in the WPF Windows Application but at a time only one splitter is working.. Why that don't know.. Plz help me out..

     

    Thank you

     

     

Semua Balasan

  • 05 April 2008 8:47
     
     

    Hi Avani,

     

    could you provide a small snippet, how you implemented your Grid Splitters. One horizontal and one vertical?

  • 07 April 2008 3:27
    Moderator
     
     

    I think that you may need to notice the GridSplitter.ResizeBehavior, ResizeDirection and ShowPreview properties. If the problem still exists, you can paste the code which can reproduce the problem, so community members can take more deep investigation on it.

     

    Best Regards,

    Wei Zhou

  • 10 April 2008 10:47
     
     
     

    Below is the code example where i am facing problem. if u run below code the gridsplitter is not moving in the  right hand side.

     

    <Grid x:Name="LayoutRoot" Background="{x:Null}">

    <DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" LastChildFill="True">

    <Grid Width="Auto" Height="Auto">

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="0.28*" MinWidth="27" x:Name="myMainGridFirstColumn"/>

    <ColumnDefinition Width="0.2*" />

    <ColumnDefinition Width="0.70*" MinWidth="7" />

    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>

    <RowDefinition Height="0.5*"/>

    <RowDefinition Height="0.5*" MaxHeight="{Binding Path=ActualHeight, ElementName=StackPanel, Mode=Default}" MinHeight="35"/>

    </Grid.RowDefinitions>

    <GridSplitter HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="myMainGridFirstColumnSplitter" Width="5" Grid.Column="1" Grid.RowSpan="2" />

    <TextBox Text="Checks" Width="251" HorizontalAlignment="Left" Grid.Column="0" Grid.RowSpan="2"></TextBox>

    <TextBox Text="Checks" Width="251" HorizontalAlignment="Left" Grid.Column="2" Grid.RowSpan="2"></TextBox>

    </Grid>

    </DockPanel>

    </Grid>

     

    please help me out in the move ment of the splitter on the both side..

     

  • 10 April 2008 16:56
     
     Jawab

    Hey try this:

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Grid>
    <Grid.Resources>
        <Style TargetType="{x:Type Rectangle}">
            <Setter Property="Margin" Value="5" />
        </Style>
    </Grid.Resources>

        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>


        <Grid Grid.Column="0" VerticalAlignment="Stretch">
            <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Rectangle Fill="LightBlue" Grid.Row="0" />
        <Rectangle Fill="AliceBlue" Grid.Row="1" />
    </Grid>

        <GridSplitter Grid.Column="1"
            Width="3" HorizontalAlignment="Center" VerticalAlignment="Stretch"
            ShowsPreview="False"></GridSplitter>
        <Grid Grid.Column="2">
        <Grid.RowDefinitions>

        <RowDefinition />
        <RowDefinition Height="Auto" />
        <RowDefinition />
        </Grid.RowDefinitions>
        <Rectangle Fill="Pink" Grid.Row="0" />
        <Rectangle Fill="Beige" Grid.Row="2" />

        <GridSplitter Grid.Row="1"
            Height="3" VerticalAlignment="Center" HorizontalAlignment="Stretch"
            ShowsPreview="False"></GridSplitter>
        </Grid>
    </Grid>
    </Page>

    Moral:
    Always set the HorizontalAlignment="Stretch" for horizontal splitter (grid).
    Always set the VerticalAlignment="Stretch" for vertical splitter (yes, grid splitter).
    It should be only stretch to fill all the space. Not any other value like center, top, botton blah blah blah..

    Hope it Works.

  • 11 April 2008 3:00
    Moderator
     
     Jawab

    I don't know very clear about your code, but I simplified your code into the following code snippet, I hope this is what you want. Furthermore, I think that you should learn more about WPF. Here is a link which contains information about WPF.

     

    Code Snippet

    <Grid>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="Auto"/>

            <ColumnDefinition Width="Auto"/>

            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>

        <TextBox Text="Checks" Width="251" HorizontalAlignment="Left" Grid.Column="0"/>

        <GridSplitter Grid.Column="1" Width="3" ResizeBehavior="PreviousAndNext"/>

        <TextBox Text="Checks" Width="251" HorizontalAlignment="Left" Grid.Column="2"/>

    </Grid>

     

     

    http://msdn2.microsoft.com/en-us/library/ms754130.aspx

     

    Best Regards,

    Wei Zhou

  • 12 April 2008 4:50
     
     Jawab

    Thank you very much..

     

    My problem is solved by setting the property HorizontalAlignment="Stretch" for horizontal splitter and  
    VerticalAlignment="Stretch" for vertical splitter.. 

     

     

  • 24 Mei 2012 17:21
     
     

    My case is a little bit different. Both Horizontal + Vertical are set to Stretch appropriately. But both gridSpliter doesn't work stable.

    The first several attempts to use the vertical GridSplitter to resize seem to meet with failure.  Seems to work the 4th time after initial startup.  Once it works, it seems to continue to work.

    Any idea how to improve this, please help.


    • Diedit oleh truyenle 24 Mei 2012 17:22
    •