WPF how to make an extension to move content

My expanding menu

Hi, I want to add a WPF control to ElementHost in my WinForms application. The behavior of my control is shown in the picture. I want to expand any extender to resize the control tree to a smaller size. And first, I want my expanders to be destroyed.

I tried so:

<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 this does not work correctly. Moreover, I would like this control to change when I resize the winForms window.

Can someone help me how to set aligment etc.

+6
source share
2 answers

Here is how I would do it ... first, I would change the Grid to the following:

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

This will give the two Expander elements as much space as they need, and the TreeView with everyone else:

 <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> 
+5
source

To make my control mutable, I switched the Dome property on ElementHost to Fill.

0
source

Source: https://habr.com/ru/post/953051/


All Articles