2010-06-07 25 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