本文介绍了WPF GridSplitter不适用于WebBrowser控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在



After:(note scrollbars)





我的XAML ...

 < Window xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
MinWidth =450
Width =450
Height =300
标题=Window3>
<网格>
< Grid.ColumnDefinitions>
< ColumnDefinition MinWidth =200Width =*/>
< ColumnDefinition Width =Auto/>
< ColumnDefinition MinWidth =200Width =*/>
< /Grid.ColumnDefinitions>
< Button Name =Button2
Grid.Column =0
Margin =5
Content =Button2/>
< GridSplitter
Width =2
Grid.Column =1
Horizo​​ntalAlignment =Center
Margin =5
面板.ZIndex =1
VerticalAlignment =Stretch
ResizeBehavior =PreviousAndNext
ResizeDirection =Columns/>
< WebBrowser
Grid.Column =2
Margin =5
Source =http://www.google.com/>
< / Grid>
< / Window>

重现问题的步骤...


  1. 将窗口的右边缘向右拖动至其宽度的两倍左右

  2. 将分离器向左拖动至最大程度即可

  3. 将窗口的右边缘向左拖动即可。

如何保留GridSplitter改变我的Grid的大小超出了Window可以包含的范围?

有人知道更多关于这个问题吗? ...或者有一个解决方法?

解决方案

我能够在ScrollViewer中使用边框进行重现(但并非没有ScrollViewer),所以我的猜测是滚动混乱了它。\\ b
$ b

在左栏设置MaxWidth(一个非常大的MaxWidth应该没有实际效果)似乎以解决它:

 < Window xmlns =http://schemas.microsoft.com/winfx/2006/xaml/演示文稿
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
Height =300
MinWidth =450
Width =450
标题=Window3>
<网格>
< Grid.ColumnDefinitions>
< ColumnDefinition MinWidth =200Width =*MaxWidth =10000/>
< ColumnDefinition Width =Auto/>
< ColumnDefinition MinWidth =200Width =*/>
< /Grid.ColumnDefinitions>
< Button
Name =Button2
Grid.Column =0
Margin =5
Content =Button2/>
< GridSplitter
Width =2
Grid.Column =1
Horizo​​ntalAlignment =Center
Margin =5
面板.ZIndex =1
VerticalAlignment =Stretch
ResizeBehavior =PreviousAndNext
ResizeDirection =Columns/>
< WebBrowser Grid.Column =2Margin =5Source =http://www.google.com/>
< / Grid>
< / Window>

看起来在某些时候,星形尺寸忽略了没有空间的事实,所以当左列达到宽度= 200,并且GridSplitter已将右列的星形大小更改为3 *左右,无论是否存在空间,列将为600.


I've been struggling with the GridSplitter. It seems to be incompatible with the WPF WebBrowser control.

If I resize my window and move the GridSplitter, then I can make my grid wider than my window and non-viewable.

Before:

WPF GridSplitter WebBrowser Before http://img239.imageshack.us/img239/4061/grid1vn8.gif

After: (note scrollbars)

WPF GridSplitter WebBrowser After http://img101.imageshack.us/img101/4303/grid2so0.gif

My XAML...

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        MinWidth="450"
        Width="450"
        Height="300"
        Title="Window3">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="200" Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition MinWidth="200" Width="*"/>
        </Grid.ColumnDefinitions>
        <Button Name="Button2"
                Grid.Column="0"
                Margin="5"
                Content="Button2"/>
        <GridSplitter
            Width="2"
            Grid.Column="1"
            HorizontalAlignment="Center"
            Margin="5"
            Panel.ZIndex="1"
            VerticalAlignment="Stretch"
            ResizeBehavior="PreviousAndNext"
            ResizeDirection="Columns"/>
        <WebBrowser
            Grid.Column="2"
            Margin="5"
            Source="http://www.google.com"/>
    </Grid>
</Window>

Steps to reproduce the problem...

  1. Drag the window's right edge to the right to about double its width
  2. Drag the splitter to the left as far as it'll go
  3. Drag the window's right edge to the left as far as it'll go.

How do I keep the GridSplitter from changing the size of my Grid beyond what the Window can contain?

Does anyone know more about this problem? ...or have a workaround?

解决方案

I was able to reproduce this with a Border in a ScrollViewer (but not without a ScrollViewer), so my guess is that the scrolling messes it up somehow.

Setting a MaxWidth on the left column (a very large MaxWidth that should have no practical effect) seemed to fix it:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300"
        MinWidth="450"
        Width="450"
        Title="Window3">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="200" Width="*" MaxWidth="10000"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition MinWidth="200" Width="*"/>
        </Grid.ColumnDefinitions>
        <Button
            Name="Button2"
            Grid.Column="0"
            Margin="5"
            Content="Button2"/>
        <GridSplitter
            Width="2"
            Grid.Column="1"
            HorizontalAlignment="Center"
            Margin="5"
            Panel.ZIndex="1"
            VerticalAlignment="Stretch"
            ResizeBehavior="PreviousAndNext"
            ResizeDirection="Columns"/>
        <WebBrowser Grid.Column="2" Margin="5" Source="http://www.google.com"/>
    </Grid>
</Window>

It appears that at some point, the star sizing overrides the fact that there's no space left, so when the left column reaches Width = 200, and the GridSplitter has changed the star size of the right column to 3* or so, the column will be 600 whether there is space or not.

这篇关于WPF GridSplitter不适用于WebBrowser控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 14:00