如何使在DockPanel中的项目拓展,以适应在WPF中的所有可用空间? [英] How to make items in a DockPanel expand to fit all available space in WPF?

查看:206
本文介绍了如何使在DockPanel中的项目拓展,以适应在WPF中的所有可用空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的StackPanel 包含的StackPanel 和其他一些物品。第一个的StackPanel 具有垂直方向,内层一个具有水平方向。内部人有一个 TreeView控件的ListView ,我想他们扩大和适应窗口的宽度,我由窗口设置,并允许用户改变。我还想外的StackPanel 以适合窗口的高度。我如何做到这一点。



编辑:
我已经转换到使用 DockPanel中,我已经在每个元素的正确设置 DockPanel.Dock 属性,并禁用了 LastChildFill 在两个dockpanels的,布局仍然没有伸展



代码:



<预类= 郎咸平的XML prettyprint-覆盖> <窗口x:类=Clippy.MainWindow
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/演示
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
标题=主窗口HEIGHT =400WIDTH =600了minHeight =400 了minWidth =600加载=Window_Loaded时,SizeChanged =Window_SizeChanged>
< DockPanel中NAME =wrapperDockPanelLastChildFill =FALSE>
<菜单高度=22NAME =MAINMENUWIDTH =自动DockPanel.Dock =顶部/>
<工具栏高度=26NAME =mainToolBarWIDTH =自动DockPanel.Dock =顶部/>
< DockPanel中高度=自动NAME =contentDockPanelDockPanel.Dock =评出的LastChildFill =FALSE>
<树视图名称=categoryTreeView/>
< ListView控件名称=clipListView/>
< / DockPanel中>
<状态条高度=23NAME =mainStatusBarDockPanel.Dock =顶部/>
< / DockPanel中>
< /窗GT;


解决方案

这应该做到这一点 - 我将它设置,使TreeView和ListView的共享主视图50/50;如果你不希望出现这种情况,将其设置为自动和*或什么的。 !使用LastChildFill你的优势



<预类=郎咸平的XML prettyprint-覆盖> <窗口x:类=Clippy.MainWindow
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
标题=主窗口HEIGHT =400WIDTH =600了minHeight =400了minWidth =600加载=Window_Loaded时,SizeChanged =Window_SizeChanged>

< DockPanel中LastChildFill =真>
<菜单WIDTH =自动DockPanel.Dock =顶部/>
<工具栏的宽度=自动DockPanel.Dock =顶部/>
<状态栏DockPanel.Dock =底/>

<网格和GT;
< Grid.RowDefinitions>
< RowDefinition HEIGHT =0.5 */>
< RowDefinition HEIGHT =0.5 */>
< /Grid.RowDefinitions>

<树视图名称=categoryTreeViewGrid.Row =0/>
< ListView控件名称=clipListViewGrid.Row =1/>
< /网格和GT;
< / DockPanel中>

< /窗GT;


I have a StackPanel containing a StackPanel and some other items. The first StackPanel has a vertical orientation, the the inner one has a horizontal orientation. The inner one has a TreeView and a ListView, I would like them to expand and fit the width of the window, which I set by the window and allow the user to change. I would also like the outer StackPanel to fit the height of the window. How do I do this?

Edit: I've converted to using a DockPanel, and I've set the DockPanel.Dock properties correctly in each of the elements, and have disabled LastChildFill in both of the dockpanels, the layout still does not stretch.

The Code:

<Window x:Class="Clippy.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="400" Width="600" MinHeight="400" MinWidth="600" Loaded="Window_Loaded" SizeChanged="Window_SizeChanged">
    <DockPanel Name="wrapperDockPanel" LastChildFill="False">
        <Menu Height="22" Name="mainMenu" Width="Auto" DockPanel.Dock="Top" />
        <ToolBar Height="26" Name="mainToolBar" Width="Auto" DockPanel.Dock="Top" />
        <DockPanel Height="Auto" Name="contentDockPanel" DockPanel.Dock="Top" LastChildFill="False">
            <TreeView Name="categoryTreeView" />
            <ListView Name="clipListView" />
        </DockPanel>
        <StatusBar Height="23" Name="mainStatusBar" DockPanel.Dock="Top" />
    </DockPanel>
</Window>

解决方案

This should do it - I set it up so that the TreeView and the ListView shared the main view 50/50; if you don't want that, set it to 'Auto' and '*' or something. Use "LastChildFill" to your advantage!

<Window x:Class="Clippy.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="400" Width="600" MinHeight="400" MinWidth="600" Loaded="Window_Loaded" SizeChanged="Window_SizeChanged">

    <DockPanel LastChildFill="True">
        <Menu Width="Auto" DockPanel.Dock="Top" />
        <ToolBar Width="Auto" DockPanel.Dock="Top" />
        <StatusBar DockPanel.Dock="Bottom" />

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="0.5*" />
                <RowDefinition Height="0.5*" />
            </Grid.RowDefinitions>

            <TreeView Name="categoryTreeView" Grid.Row="0" />
            <ListView Name="clipListView" Grid.Row="1" />
        </Grid>
    </DockPanel>

</Window>

这篇关于如何使在DockPanel中的项目拓展,以适应在WPF中的所有可用空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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