2011-03-21 51 views
1

我有一个列表框模板,显示一个图像和三个文本框。你会看到他们如何分配在下面的代码。我的问题是有些项目没有图像,我希望文本填充整行。 我试过不使用网格,使用画布,但我不知道为什么,当在列表框中使用画布时,什么都不显示。我不知道这是否容易完成。代码如下:列表框模板,隐藏元素

<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> 

谢谢!

+1

我不能看到你在你所提供的代码中使用'Canvas',但** **填充值应该是逗号分隔,不占空间:'填充=“0, 0,25,0“' – 2011-03-21 15:37:07

+0

感谢您指出逗号缺少 – enkara 2011-03-22 08:54:23

回答

1

有几种方法可以将它们绑定在一起。

的一种方式是:

  • 添加一些填充到边框
  • 绑定边框缩略图属性的使用适当ValueConverter
  • 变化列0的从“60”的宽度的可见性到“自动” - 当图像被折叠时它将消失。
+0

我已经找到了关于如何使用转换器的示例(http://stackoverflow.com/questions/4695057/formatting-a-date-in-xaml-on -wp7),但我的xaml无法识别单词命名空间。如何将转换器定义为资源? – enkara 2011-03-22 09:07:22

+1

你需要定义你的命名空间 - 在你的xaml的第一个声明中,添加类似xmlns:mynamespace =“clr-namespace:MyProject.Converters”,这将允许你使用“mynamespace:MyConverter”来包含你的转换器 – Stuart 2011-03-22 09:14:25

+0

太棒了!感谢您的帮助。我想我需要一本关于silverlight的好手册 – enkara 2011-03-22 09:25:50