'ListViewItem Trigger messed up the ListView
I have already tried googling this problem, but just couldn't find a solution. So my problem is that when putting the trigger into the code, it just messes it up, or to be more exact, the data I inputted by binding it, doesn't show up. The whole part between ListView.Resources is the problem, since I tried it whithout that part, and the data worked fine.
Just to clear some things up: Yes the code does work(just the data doesn't show up) and the trigger does too(when mouse is over it turns red).
<ListView Name="benutzerListe" ItemsSource="{Binding BDatens}" BorderBrush="Black" BorderThickness="5" Background="White" Height="450" Width="800" Margin="90 180 90 0" HorizontalAlignment="Center" VerticalAlignment="Top" SelectionMode="Extended" >
<ListView.Resources>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border x:Name="Bd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="Transparent"
Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="Bd" Value="Red"/>
<Setter Property="BorderBrush" TargetName="Bd" Value="#A826A0DA"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Id" Width="145">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Id}" FontSize="15"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Vorname" Width="210">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Vorname}" FontSize="15"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Nachname" Width="210">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Nachname}" FontSize="15"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Passwort" Width="220" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Passwort}" FontSize="15"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Height" Value="30"/>
<Setter Property="FontSize" Value="17"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Background" Value="DarkRed"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
</GridView>
</ListView.View>
</ListView>
The Window should show the ListView with the Items and their data(Id's, surname's, name's, password's) but only "ePharmacy.BDaten" shows up.
Does anyone know how to solve this problem? So that I can see the data + trigger?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
