繁体   English   中英

WPF如何使扩展器移动内容

[英]WPF how to make expander move content

我的扩展菜单

您好我希望在我的WinForms应用程序中添加WPF控件到ElementHost。 我的控制行为如图所示。 我希望扩展任何扩展器使我的treeview控件调整为更小的大小。 一开始我希望我的扩张器倒塌。

我是这样尝试的:

<UserControl x:Class="LeftPane"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" >
<Grid VerticalAlignment="Stretch" Margin="3,3,3,3">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>            
    </Grid.RowDefinitions>
    <TreeView Grid.Row="0" Name="treeView1" VerticalAlignment="Stretch" >

    </TreeView>
    <StackPanel  Grid.Row="1" Name="StackPanel1" VerticalAlignment="Bottom">
        <ListBox SelectedIndex="1">
            <ListBoxItem VerticalAlignment="Stretch">
                <Expander Grid.Row="1" ExpandDirection="Down" Header="expander1" VerticalAlignment="Stretch" Name="expander1" IsExpanded="False">
                    <ListBox>
                        <ListBoxItem Content="Unit 1"/>
                        <ListBoxItem Content="Unit 2"/>
                    </ListBox>
                </Expander>
            </ListBoxItem>
            <ListBoxItem VerticalAlignment="Stretch">
                <Expander Grid.Row="2" ExpandDirection="Down" Header="expander2" VerticalAlignment="Stretch" Name="expander2" IsExpanded="False">
                    <ListBox>
                        <ListBoxItem Content="Unit 1"/>
                        <ListBoxItem Content="Unit 2"/>
                    </ListBox>
                </Expander>
            </ListBoxItem>
        </ListBox>
    </StackPanel>
</Grid>

和:

public void AddControl(ElementHost host)
    {
        this.parentHost = host;
        host.Child = this;
        this.Height = host.Size.Height;
        treeView1.MaxHeight = this.Height - 60;

    }

但它无法正常工作。 更重要的是,当我调整winForms窗口大小时,我希望此控件可以调整大小。

任何人都可以帮我如何设置对等等

这就是我实现这一目标的方法......首先,我将Grid更改为以下内容:

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

这将为两个Expander控件提供所需的空间,并为所有其余的TreeView提供:

<TreeView Grid.Row="0" Name="treeView1" />
<Expander Grid.Row="1" Header="expander1" Name="expander1" IsExpanded="False">
    <ListBox>
        <ListBoxItem Content="Unit 1"/>
        <ListBoxItem Content="Unit 2"/>
    </ListBox>
 </Expander>
<Expander Grid.Row="2" Header="expander2" Name="expander2" IsExpanded="False">
    <ListBox>
        <ListBoxItem Content="Unit 1"/>
        <ListBoxItem Content="Unit 2"/>
    </ListBox>
 </Expander>

为了使我的控件可调整大小,我将ElementHost属性Dock切换为Fill。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM