Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF C#4.0
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
<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 23-Jan-14 21:18pm
CS201118.8K
Edited 23-Jan-14 23:38pm
VUnreal10K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
<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>
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web01 | 2.8.141015.1 | Last Updated 24 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100