ListViewの行の背景色を個別に変更したいと思います。私はそうすることができましたが、各行の間に白さの2つのピクセルがあります。私は2つの行が同じ色を持っているときに、それらの間に目に見える区切りがないように空白を削除したい。ListViewの行全体の色を設定する方法/ ListViewの行間のスペースをなくす方法はありますか?
加え、行が選択され、またははmousedオーバーされた場合、その背景色が非表示になっています。もう一度見えるようにすることはできますか?
コード例(私の実際のコードでは、私はデータバインディングによるカラーを選択):
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<!--Doesn't help!-->
<Setter Property="Margin" Value="0 0 0 0"/>
<Setter Property="Padding" Value="0 0 0 0"/>
<Setter Property="Background" Value="Lime"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Width="120" Header="Date" />
<GridViewColumn Width="120" Header="Day Of Week"
DisplayMemberBinding="{Binding DayOfWeek}" />
<GridViewColumn Width="120" Header="Year"
DisplayMemberBinding="{Binding Year}" />
</GridView>
</ListView.View>
<sys:DateTime>1/2/3</sys:DateTime>
<sys:DateTime>4/5/6</sys:DateTime>
<sys:DateTime>7/8/9</sys:DateTime>
<sys:DateTime>10/11/12</sys:DateTime>
</ListView>
</Grid>
</Window>
私はあなたのコードを試して、それはうまくいきました、行にはギャップがありません。 ListView.ItemContainerStyleの負のマージンを設定してみてください。 隠された背景であなたは何をしていますか?選択された行は強調表示されますが、選択解除すると前の状態に戻ります。 – icebat
アイテムが強調表示されているとき、ユーザーはそのアイテムの色を確認できません。選択矩形のみを表示したり、背景色とブレンドする方がはるかに良いでしょう。 – Qwertie