Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
WPF GridSplitter and browser control doesn't work as expected. when I move the GridSplitter the content spills out of window. This happens when you give default width to the browser control. Any idea how to fix this?

Sample code
XML
<Window x:Class="htmlBrowserControl.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid removed="AliceBlue">
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition />
            <ColumnDefinition Width="500"/>
        </Grid.ColumnDefinitions>
        <GridSplitter Grid.Column="1" Width="5" ></GridSplitter>
        <!--<Grid Grid.Column="2">-->
            <!--<ContentControl>-->
        <WebBrowser Grid.Column="2" Source="C:\HelpConfig\PSCHelp.html" Width="500" ></WebBrowser>
            <!--</ContentControl>-->
        <!--</Grid>-->
    </Grid>
</Window>
Posted
Updated 16-Oct-17 0:55am
v2

1 solution

You're not giving it the default width. You're giving it the width. That's why it's getting pushed out. The GridSplitter controls the width of the cell that it's in. I think your XAML is wrong in that regard, because you have it in it's own cell.

You can define some constraints by specifying MinWidth values. WPF frowns on hardcoding height and width values. Here's what I think you want.

HTML
<window x:class="CpGridSplitter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="550" MinWidth="550">
    <grid>
        <grid.columndefinitions>
            <columndefinition width="Auto" minwidth="50" />
            <columndefinition minwidth="500" />
        </grid.columndefinitions>
        <button grid.column="0" content="Foo" />
        <gridsplitter grid.column="0" width="5" />
        <webbrowser grid.column="1" source="http://www.bing.com" />
    </grid>
</window>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900