当列表中包含的项目数增加时,我想动态地更改ListView项目面板的高度。
这是在XAML中设置ListView的方式:
<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>
我的ListView“ listANALOG”像下面这样填充在代码中:
listANALOG.ItemsSource = hConfig.listANALOG;
我的问题是我无法使用WrapPanel的高度(pnlAnalog)来增加它。
我不会设计这样的IHM,但是它是一个旧软件,我们没有足够的资源来重写它。
谢谢您的帮助。
答案 0 :(得分:2)
您可以使用this WrapPanel
方法获得对FindChild<T>
的引用:
WrapPanel wrapPanel = FindChild<WrapPanel>(listANALOG, "pnlAnalog");
wrapPanel.Height = 500;