Alexus
Alexus

Reputation: 296

Change ListView ItemsPanels height dynamicaly

I'd like to change a ListView items panel height dynamicaly when the number of items it contains increase.

This is how my ListView is set in XAML :

<ListView x:Name="listANALOG" BorderThickness="0" Padding="0" Margin="4,4,4,4" Background="MediumPurple" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Row="2" Grid.ColumnSpan="2">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Border BorderBrush="DarkOrange" Background="{Binding EtatCMD}" BorderThickness="2"  MouseDown="WrapPanel_MouseDown" Margin="-4,0,-2,0">
                <DockPanel  Width="65" Height="65" Margin="2" LastChildFill="True" >
                    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Height="10" IsHitTestVisible="False" Margin="0">
                        <Ellipse Fill="{Binding Trigger1}" Height="10" Margin="2,0,0,0" Width="10" />
                        <Ellipse Fill="{Binding Trigger2}" Height="10" Margin="2,0,0,0" Width="10" Opacity="{Binding ShowTrigger2}"/>
                        <Ellipse Fill="{Binding Trigger3}" Height="10" Margin="2,0,0,0" Width="10" Opacity="{Binding ShowTrigger3}"/>
                    </StackPanel>
                    <Label DockPanel.Dock="Top" Content="{Binding Name}"  FontSize="10" Margin="0" FontWeight="DemiBold" HorizontalAlignment="Left" VerticalAlignment="Center" Padding="0" ToolTip="Used in :" ToolTipOpening="Label_ToolTipOpening_2"/>
                    <Label DockPanel.Dock="Bottom" Content="{Binding CommandeStr}" Margin="0" Padding="0" HorizontalAlignment="Left" VerticalAlignment="Bottom" IsHitTestVisible="False"/>
                    <TextBox  MaxLength="14" Text="{Binding UserName}" Margin="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Background="Transparent" BorderThickness="0" Padding ="0" VerticalAlignment="Top" TextWrapping="Wrap"/>
                </DockPanel>
            </Border>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel x:Name="pnlAnalog" Orientation="Vertical" VerticalAlignment="Stretch" Height="185"/>
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
</ListView>

My ListView "listANALOG" is populated in code behind like this :

listANALOG.ItemsSource = hConfig.listANALOG;

My issue is that I can't have access to the WrapPanel's height (pnlAnalog) to increase it.

I wouldn't have design an IHM like this, but it's an old software, we don't have enough ressources to re-write it.

Thank you for your help.

Upvotes: 1

Views: 43

Answers (1)

mm8
mm8

Reputation: 169340

You could get a reference to the WrapPanel using this FindChild<T> method:

WrapPanel wrapPanel = FindChild<WrapPanel>(listANALOG, "pnlAnalog");
wrapPanel.Height = 500;

Upvotes: 2

Related Questions