我有一个 ItemsControl,想从我的 CustomObject 中显示一些字符串。
就像是
String A
String B
String C
其中字符串 A 和 B 可以是多行,但 C 不能。我在想Height="Auto"
和一个DockPanel。字符串 A 的高度应该是它需要的高度。字符串 B 也是如此。
到目前为止,这是我想出的:
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Background="Black">
<ItemsControl Name="ItemsControl1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="#FF126eb1" BorderThickness="1.5" CornerRadius="8,8,8,8" Background="#FF074e84" Width="350" Height="Auto">
<DockPanel Width="350" Margin="0,10,0,0" Height="Auto" Background="Transparent">
<Canvas DockPanel.Dock="Top" Height="Auto" Width="350" Margin="0,10,0,0">
<TextBlock Text="{Binding Headline}" Canvas.Left="5" Canvas.Top="5" Foreground="White" FontSize="15" FontWeight="Bold" MaxWidth="340" TextWrapping="Wrap" Height="Auto"/>
</Canvas>
<Canvas DockPanel.Dock="Top" Height="Auto" Width="350" Margin="0,10,0,0">
<TextBlock Text="{Binding Description}" Canvas.Left="5" Canvas.Top="20" Foreground="White" FontSize="13" MaxWidth="340" TextWrapping="Wrap" Height="Auto" />
</Canvas>
<Canvas DockPanel.Dock="Top" Width="350" Height="40" Margin="0,10,0,0" Background="Transparent">
<TextBlock Text="{Binding DeadlineOn, StringFormat='Deadline: {0}'}" Canvas.Left="5" Canvas.Top="5" Foreground="White"/>
<!-- and other controls -->
</Canvas>
</DockPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
不幸的是,只有 margin 属性在为字符串 A 和 B 创建高度。
如果每个项目的高度未知,我该怎么做?