J'ai défini le style pour ma liste de WPF mais j'ajoute un rectangle manuellement en haut ... de toute façon pour le construire dans la liste elle-même? Donc, actuellement, j'écris le XAML pour un rectangle, puis ajoutez une zone de liste ci-dessous pour l'effet final: Ajouter un rectangle à ListBox
style pour la zone de liste
<Style BasedOn="{StaticResource {x:Type ListBox}}"
TargetType="ListBox"
x:Key="PinnedList">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0" Color="#90DDDD" />
<GradientStop Offset="1.0" Color="#5BFFFF" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border Name="Border" Background="{StaticResource WhiteSolid}" BorderBrush="{StaticResource GreatTeaHeaderBrush}" BorderThickness="4" CornerRadius="2">
<ScrollViewer Margin="0" Focusable="false">
<StackPanel Margin="2" IsItemsHost="True" />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Ce que je dois faire actuellement pour obtenir l'effet (rectangle puis la zone de liste):
<Rectangle Height="20" Width="20" Fill="{StaticResource GreenTeaBrush}" Margin="-7,37,129,0" VerticalAlignment="Top" x:Name="ui_recPinnedORGs">
<Rectangle.LayoutTransform>
<RotateTransform Angle="-45"/>
</Rectangle.LayoutTransform>
</Rectangle>
<ListBox Style="{StaticResource PinnedList}" Height="Auto" MaxHeight="200" Visibility="Hidden" HorizontalAlignment="Left" Margin="-8,45,0,0" SelectionChanged="ui_lsbPinnedORGs_SelectionChanged"
SelectedItem="{Binding Path=SelectedPinnedORGsViewModel, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}"
SelectionMode="Single" ItemsSource="{Binding Path=ORGViewModels, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, Mode=TwoWay}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
VerticalAlignment="Top" Width="158" Name="ui_lsbPinnedORGs">
<ListBox.ItemTemplate>
<HierarchicalDataTemplate>
<Label Content="{Binding Path=ORG.Acronym, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" />
</HierarchicalDataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Essayez Style sur ListBoxItem (non ListBox) – Paparazzi
Merci Blam, mais la réponse ci-dessous fonctionne bien :) –