WPF GridSplitter和浏览器控件不起作用 [英] WPF GridSplitter and browser control doesn't work

查看:181
本文介绍了WPF GridSplitter和浏览器控件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF GridSplitter和浏览器控件无法正常工作。当我移动GridSplitter时,内容溢出窗口。当您为浏览器控件提供默认宽度时会发生这种情况。知道怎么解决这个问题吗?



示例代码

 <  窗口    x:Class   =  htmlBrowserControl.MainWindow  

xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation

xmlns:x = http://schemas.microsoft.com/winfx/2006/xaml\"

标题 = < span class =code-keyword> MainWindow 高度 = 350 宽度 = 525 >
< 网格 已删除 = AliceBlue >
< < span class =code-leadattribute> Grid.ColumnDefinitions >
< ColumnDefinition / >
< ColumnDefinition / >
< ColumnDefinition 宽度 = 500 / >
< /Grid.ColumnDefinitions>
< GridSplitter Grid.Column = 1 宽度 = 5 > < / GridSplitter >
<! - < Grid Grid.Column =2> - > ;
<! - < ContentControl> - >
< WebBrowser Grid.Column = 2 Source = C:\ HelpOf ig\PSCHelp.html 宽度 = 500 > < / WebBrowser >
< ;! - < / ContentControl> - > ;
<! - < / Grid> - >
< / Grid >
< ; / Window >

解决方案

你没有给它默认宽度。你给它 宽度。这就是它被推出的原因。 GridSplitter控制它所在的单元格的宽度。我认为你的XAML在这方面是错误的,因为你把它放在它自己的单元格中。



你可以定义指定MinWidth值的一些约束。 WPF对硬编码的高度和宽度值皱眉。这就是我认为你想要的。



 <  窗口    x:class   =  CpGridSplitter.MainWindow  

xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation

xmlns:x = http://schemas.microsoft .com / winfx / 2006 / xaml

< span class =code-attribute>
标题 = MainWindow 高度 = 350 宽度 = 550 MinWidth = 550 >
< 网格 >
< grid.columndefinitions >
< columndefinition width = 自动 minwidth = 50 < span class =code-attribute> / >
< columndefinition minwidth = 500 / >
< ; / grid.columndefinitions >
< 按钮 grid。列 = 0 content = Foo / < span class =code-keyword>>
< gridsplitter grid.column = 0 width = 5 / >
< webbrowser grid.column = 1 来源 = http://www.bing.com / >
< / grid >
< / window >


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>

解决方案

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>


这篇关于WPF GridSplitter和浏览器控件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆