【发布时间】:2018-03-02 12:28:00
【问题描述】:
我有一个列表框,上面显示一个图像和一个文本。我已将 DataTemplate 绑定到具有字符串 Str 和图像 Image 的自定义 MyImage 类。由于周围的 StackPanel 是水平的,因此下一个图像将出现在第一个图像的右侧。
我无法将图像的高度设置为填充整个列表框高度减去文本高度和边距的值。
在下面的代码中,我将它绑定到 ListBox listboxMyImages 的 ActualHeight。
我希望现在能够从该值中减去 TextBlock 的高度。最好的方法是什么?
<ListBox x:Name="listboxMyImages" Margin="10,10,10,10">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type local:MyImage}">
<StackPanel>
<TextBlock x:Name="lblMyImage" Margin="3" Text="{Binding Str}" />
<Image Margin="3" Source="{Binding Image}" Height="{Binding ElementName=listboxMyImages, Path=ActualHeight }"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
【问题讨论】: