2009-09-11 4 views
1

J'essaie de créer une zone de liste dans laquelle j'ai un contrôle total sur l'aspect de chaque élément de la zone de liste.Le contenu ListBox ne s'étire pas complètement sur la zone de liste

Je peux étendre l'élément horizontalement. Cependant, il y a ce mince ruban de bleu à gauche d'un élément sélectionné. (Sur l'image, l'élément du milieu est sélectionné). Puis-je faire disparaître cette bande bleue?

alt text http://img44.imageshack.us/img44/949/boundlistboxdisplay.jpg

Voici le code complet.

<Window x:Class="SimpleListTemplate.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    > 
    <Window.Resources> 
     <XmlDataProvider x:Key="DcCharacters"> 
      <x:XData> 
       <Characters xmlns=""> 
        <Character HeroName="Catwoman" Identity="Selina Kyle" /> 
        <Character HeroName="Batman" Identity="Bruce Wayne" /> 
        <Character HeroName="Starman" Identity="Jack Knight" /> 
       </Characters> 
      </x:XData> 
     </XmlDataProvider> 
    </Window.Resources> 
    <Grid> 
     <ListBox 
      ItemsSource="{Binding Source={StaticResource DcCharacters}, XPath=//Characters/*}" 
      HorizontalContentAlignment="Stretch"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <Label 
         Content="{Binding [email protected]}" 
         Height="40" 
         VerticalContentAlignment="Center" 
         Background="LightGreen" 
         BorderThickness="2" 
         BorderBrush="DarkGreen"/> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 
    </Grid> 
</Window> 
+1

Duplicata de http://stackoverflow.com/questions/837993/how-to-remove-the-left-hand-blue-line-on-custom-selected-styled-listbox-items/ –

Répondre

1

Voici une mise à jour pour votre code.

<Window x:Class="SimpleListTemplate.Window1"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Window.Resources> 
    <XmlDataProvider x:Key="DcCharacters"> 
     <x:XData> 
      <Characters xmlns=""> 
       <Character HeroName="Catwoman" Identity="Selina Kyle" /> 
       <Character HeroName="Batman" Identity="Bruce Wayne" /> 
       <Character HeroName="Starman" Identity="Jack Knight" /> 
      </Characters> 
     </x:XData> 
    </XmlDataProvider> 
    <Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle"> 
     <Setter Property="Padding" Value="0,0,0,0"/> 
    </Style> 
</Window.Resources> 
<Grid> 
    <ListBox 
     ItemsSource="{Binding Source={StaticResource DcCharacters}, XPath=//Characters/*}" 
     ItemContainerStyle="{StaticResource ContainerStyle}" 
     HorizontalContentAlignment="Stretch"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Label 
        Content="{Binding [email protected]}" 
        Height="40" 
        VerticalContentAlignment="Center" 
        Background="LightGreen" 
        BorderThickness="2" 
        BorderBrush="DarkGreen"/> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
</Grid> 
</Window> 

Cela peut résoudre votre problème.

Questions connexes