WPF如何使擴展器移動內容

[英]WPF how to make expander move content


My expanding menu

Hi I wish to add WPF control to ElementHost in my WinForms application. The behavior of my control is depicted on picture. I wish expanding any expander make my treeview control resize to smaller size. And on the beginning I wish my expanders to be collapsed.

嗨,我希望在我的WinForms應用程序中添加WPF控件到ElementHost。我的控制行為如圖所示。我希望擴展任何擴展器使我的treeview控件調整為更小的大小。一開始我希望我的擴張器倒塌。

I was trying sth like that:

我是這樣嘗試的:

<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>

and:

和:

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

    }

But it doesn't work correctly. What is more I would like this control resize while I resize my winForms window.

但它無法正常工作。更重要的是,當我調整winForms窗口大小時,我希望此控件可以調整大小。

Can anyone help me how to set aligment etc.

任何人都可以幫我如何設置對等等

2 个解决方案

#1


5  

This is how I would achieve this... first, I would change the Grid to the following:

這就是我實現這個目標的方法......首先,我將Grid更改為以下內容:

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

This will provide the two Expander controls with as much space as they need and the TreeView with all of the rest:

這將為兩個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>

#2


0  

To make my control resizable, I switched ElementHost property Dock to Fill.

為了使我的控件可調整大小,我將ElementHost屬性Dock切換為Fill。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/09/03/72f38371e8f28c633068fa96d54ebc42.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com