<Style TargetType="ListBox"> <Setter Property="ItemContainerStyle"> <Setter.Value> <Style TargetType="ListBoxItem"> <Setter Property="Padding" Value="0"/> <Setter Property="Margin" Value="0,0,5,0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border x:Name="relateItemborder" Height="20" HorizontalAlignment="Stretch" Width="{Binding Path=ActualWidth,ElementName=StackPanelRelatedProtocol}" Style="{DynamicResource ListItemBorderSty}"> <StackPanel Orientation="Horizontal" x:Name="StackPanelRelatedProtocol"> <TextBlock Text="{Binding Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" x:Name="tbprotocolname" FontSize="14" Margin="10,0,5,0"/> <Button Command="{Binding ElementName=self, Path=DataContext.RemoveRelatedProtocolCommand}" CommandParameter="{Binding Name}" Tag="{Binding Name}" Style="{DynamicResource PublicCloseButton}" Width="30" Height="20"/> </StackPanel> </Border> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter TargetName="relateItemborder" Property="Background" Value="#C7D7DB"/> <Setter TargetName="relateItemborder" Property="BorderBrush" Value="#6F9CB1"/> <Setter TargetName="relateItemborder" Property="BorderThickness" Value="1"/> </Trigger> <Trigger Property="IsFocused" Value="false"> <Setter TargetName="relateItemborder" Property="Background" Value="#BEBFBF"/> <Setter TargetName="relateItemborder" Property="BorderBrush" Value="#979797"/> <Setter TargetName="relateItemborder" Property="BorderThickness" Value="1"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </Setter.Value> </Setter> </Style>
标签:ListBox,Template,ItemContainerStyle From: https://www.cnblogs.com/LXLR/p/16785398.html