このコードは、デフォルトの選択スタイルをListBoxのSelect ListBoxItemのカスタムスタイルに置き換えています。ただし、パディングや余白の変更では削除できない既定のスタイルから、左に少し青い線が残ります。選択したカスタムスタイルのリストボックスアイテムの左側の青い線を削除するにはどうすればよいですか?
青い線を削除して、選択したListBoxItemのスタイルを完全に決定するにはどうすればよいですか?
alt text http://tanguay.info/web/external/blueLineLeft.png
<Window x:Class="CodingContext.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CodingContext"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate" DataType="{x:Type local:Person}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=Name, StringFormat=Name: \{0\}}" />
<TextBlock Grid.Column="1" Text="{Binding Path=Age, StringFormat=Age: \{0\}}" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="SelectedTemplate" DataType="{x:Type local:Person}">
<Grid Background="Yellow">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Foreground="Black" Grid.Row="0" Grid.Column="0" Text="Person" FontSize="14" FontWeight="Bold" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Path=Name, StringFormat=Name: \{0\}}" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Age, StringFormat=Age: \{0\}}" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Address" FontSize="14" FontWeight="Bold" />
<StackPanel Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<TextBlock Text="{Binding Address}" />
<TextBlock Text="{Binding City, StringFormat= \{0\}}" />
<TextBlock Text="{Binding State, StringFormat= \{0\}}" />
<TextBlock Text="{Binding Zip, StringFormat= \{0\}}" />
</StackPanel>
</Grid>
</DataTemplate>
<Style TargetType="{x:Type ListBoxItem}" x:Key="ContainerStyle">
<Setter Property="ContentTemplate" Value="{StaticResource ItemTemplate}" />
<Setter Property="Margin" Value="5" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SelectedTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<ListBox HorizontalContentAlignment="Stretch" Margin="10" x:Name="lstPeople" ItemsSource="{Binding People}" ItemContainerStyle="{StaticResource ContainerStyle}" />
</Window>
はい、それを元に戻ってパディングを取得する必要があります(私はそれぞれの子のtextblocksに余白を適用しなければならなかった、パディングのボーダーは青い線を取り戻していました)。 。 –