我有一个列表框模板,显示一个图像和三个文本框。你会看到他们如何分配在下面的代码。我的问题是有些项目没有图像,我希望文本填充整行。 我试过不使用网格,使用画布,但我不知道为什么,当在列表框中使用画布时,什么都不显示。我不知道这是否容易完成。代码如下:列表框模板,隐藏元素
<ListBox Grid.Column="0" Grid.Row="1" Background="White" HorizontalAlignment="Stretch" Name="itemList" VerticalContentAlignment="Stretch" SelectionChanged="listBoxSetmana_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="480">
<Grid.RowDefinitions>
<RowDefinition Height="28" />
<RowDefinition Height="17" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.RowSpan="3" Grid.Column="0" Grid.Row="0" BorderThickness="1" BorderBrush="#FFFF003F" Padding="1">
<Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="listImage" Width="36" Height="36" Source="{Binding thumbnail}" />
</Border>
<TextBlock Padding="0 0 25 0" Grid.Column="1" Grid.Row="0" Name="title" Foreground="Black" Text="{Binding title}" FontWeight="Bold" FontSize="20" />
<TextBlock Padding="0 0 25 0" Grid.Column="1" Grid.Row="1" Name="published" Foreground="Black" Text="{Binding published}" FontSize="13" />
<TextBlock Padding="0 0 25 0" Grid.Column="1" Grid.Row="2" Name="subtitle" Foreground="Black" Text="{Binding subtitle}" FontSize="16" TextWrapping="Wrap" />
<TextBlock Visibility="Collapsed" Text="{Binding id}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
谢谢!
我不能看到你在你所提供的代码中使用'Canvas',但** **填充值应该是逗号分隔,不占空间:'填充=“0, 0,25,0“' – 2011-03-21 15:37:07
感谢您指出逗号缺少 – enkara 2011-03-22 08:54:23