I have a Listview that has three columns. The last columns holds an image that only gets displayed if the data the column bind to is true.
<ListView HorizontalAlignment="Stretch" Margin="5" VerticalAlignment="Stretch" Name="lstPrinters" ItemsSource="{Binding PrinterCollection}">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Width="250" Header="UNC" DisplayMemberBinding="{Binding UNC}" />
<GridViewColumn Width="50" Header="Default" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
<Image Width="16" Height="16" Source="/PrinterController.Agent;component/images/GreenTick.png">
<Image.Style>
<Style TargetType="{x:Type Image}" >
<Style.Triggers>
<DataTrigger Binding="{Binding IsDefault}" Value="false">
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
<DataTrigger Binding="{Binding IsDefault}" Value="true">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
I want the image to be horizontially centred in the column but no matter how I try it wont center. I have tried so many ways to do this to be honest I am starting to forget what I have and haven’t tried! I have followed all the SO articles I can find that relate to this issue but none have worked. I only want this one column to be centred.
Any pointers would be appreciated.
Add this to your ListView: