2010-06-07 45 views
2

我刚刚开始使用Visual Studio 2010 Express for Windows Phone进行开发,并将其放入ListBox中。我似乎无法操纵格式。不管我做什么,背景是黑色/灰色,选定的项目都有一个蓝色边框,并且在列表框中的项目之间有填充(我正在使用图像)。这里是我的代码:Windows Phone 7列表框不可自定义?

的XAML:

<Grid x:Name="ContentGrid" Grid.Row="1"> 
    <Grid Name="gallery"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="370" /> 
      <RowDefinition Height="150" /> 
     </Grid.RowDefinitions> 
     <Border BorderBrush="Red" Width="450" CornerRadius="4" BorderThickness="2" 
      Background="Red" Margin="10,30,20,10" Padding="6,6,6,6"> 
      <Image Grid.Row="0" Grid.Column="0" Height="360" x:Name="imgPreview"/> 
     </Border> 
     <ListBox x:Name="lbScrollGallery" Grid.Row="1" Grid.Column="0" Padding="0" 
       VerticalAlignment="Top" Width="450" SelectionChanged="ScrollerSelectionChanged" 
       d:LayoutOverrides="HorizontalAlignment" ScrollViewer.HorizontalScrollBarVisibility="Hidden"> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel Orientation="Horizontal"/> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <Image Width="100" Height="100" Stretch="Fill" Name="imgSource" 
         VerticalAlignment="Center" 
         Source="{Binding Path=Url}" /> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 
    </Grid> 
</Grid> 

有一些方法我可以自定义列表框?就像将背景改为红色或在不同项目之间填充0一样?

+0

如果按照建议执行,比如实现自己的样式等,则应该能够像桌面上的Silverlight一样覆盖列表框的默认样式 - 请记住,某些填充用于触摸目标,值得在构建自定义控件时记住或者定制现有的图像 - 但是图像将会大到我猜想的目标。 – RoguePlanetoid 2010-06-08 18:57:06

回答

7

这里是一些演示xaml,显示设置一些显示属性。

<ListBox Height="640" HorizontalAlignment="Left" Margin="6,6,0,0" Name="listBox1" VerticalAlignment="Top" Width="468"> 
     <ListBox.ItemContainerStyle> 
      <Style TargetType="ListBoxItem"> 
       <Setter Property="Padding" Value="-12" /> 
       <Setter Property="Background" Value="White"/> 
       <Setter Property="Foreground" Value="Black"/> 
      </Style> 

     </ListBox.ItemContainerStyle> 
    </ListBox> 

请注意,内置格式是应用一些填充,它可以解决-12的值。我也从Eric Fleck的帖子here了解到,这可能是地铁造型的结果。这篇文章提供了一个如何在按钮控件上全部绕过这种格式的例子。这可能是一个值得考虑的方法。

+0

谢谢树,工作。 – EverTheLearner 2010-06-08 20:56:34

+0

通常不建议您“绕过”Metro样式准则,因为它们有助于在应用程序之间保持一致的UX。用一些额外的空间击中目标对于像我这样的胖手指真的很有帮助... – 2010-08-06 05:34:53

1

您应该先看看at this MSDN article关于Silverlight(和WPF)中的模板和样式。每个控件都是可定制的,只需在这里提供您自己的TemplateItemsContainerStyle