C# 如何填写DockPanel?

C# 如何填写DockPanel?,c#,.net,wpf,C#,.net,Wpf,我有一个.xaml代码: <Window x:Class="Eagle_Eye.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/b

我有一个.xaml代码:

<Window x:Class="Eagle_Eye.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Eagle_Eye"
        mc:Ignorable="d"
        ResizeMode="NoResize"
        Title="EE" Height="450" Width="800">
    <Grid>
        <DockPanel>
            <StackPanel Orientation="Vertical" DockPanel.Dock="Top" Margin="0" >
            </StackPanel>
            <StackPanel Orientation="Vertical" DockPanel.Dock="Top"  >
                <TextBlock Name="debugText" Height="20" Background="Azure" Foreground="Red"></TextBlock>
            </StackPanel>



        <WebBrowser Name="webBrowser" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></WebBrowser>
        </DockPanel>



    </Grid>
</Window>

这个.cs代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Eagle_Eye
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            debugText.Text = "hello";
            webBrowser.Navigate("https://www.google.com");
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
鹰眼
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
debugText.Text=“你好”;
webBrowser.Navigate(“https://www.google.com");
}
}
}
它给我的是:

它只占屏幕的一半,还有滚动条。我错过了什么

我想要的是:

*黄色框应包含
TextBlock
,蓝色框应包含
WebBrowser
,不带滚动条,拉伸*


我怎样才能做到这一点呢?

这里有几个问题, 首先,Dockpanel默认具有“LastChildFill”选项,这意味着最后一个子面板将填充面板的其余部分,如果将最后一个子面板绑定到底部,它将不会拉伸。。 其次,stackpanel项目不会拉伸,并且始终尝试占用最小的空间

所以我要做的是替换:

        <StackPanel Orientation="Vertical" DockPanel.Dock="Bottom">
            <WebBrowser Name="webBrowser"></WebBrowser>
        </StackPanel>

为此:

            <WebBrowser Name="webBrowser" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></WebBrowser>


谢谢您提供了一半的解决方案。您能帮我解决剩下的问题吗?请看问题,我已经编辑过了。虽然我不熟悉web浏览器组件,但我认为滚动条的出现是因为它的最小尺寸要求未得到满足。您可能可以禁用滚动条可见性,但窗口看起来不太好。或者您正在询问如何允许调整窗口的大小?(这些都是通过窗口控件上的NoResize=False、CanMinimize=True、CanResize=True来控制的)在搜索了很多之后,我发现这是无法做到的。嗯,不是不可能,但对这里来说太宽了。所以我减少了这个问题。