您好我希望在我的 WinForms 应用程序中将 WPF 控件添加到 ElementHost。我的控件的行为如图所示。我希望扩展任何扩展器使我的树视图控件调整为更小的尺寸。一开始我希望我的扩展器可以折叠起来。
我正在尝试这样的事情:
<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 窗口大小时调整此控件的大小。
谁能帮助我如何设置对齐等。