Hi iam using a listbox to show a list of items. in the listbox i ahve an togglebutton on every item. When i click on the toggle button the state of the togglebutton is pressed. But when i am scrolling down in the listbox and scolls up again. The togglebutton state is not pressed. How can i prevent this please help.
Heres my itemtemplate
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,3,0,0">
<Border BorderBrush="Black" BorderThickness="1,1,1,1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
<GradientStop Color="#FFECECEC" Offset="1"/>
<GradientStop Color="#FFE8E8E8"/>
<GradientStop Color="#FFBDBDBD" Offset="0.153"/>
<GradientStop Color="#FFE8E8E8" Offset="0.904"/>
</LinearGradientBrush>
</Border.Background>
<Border.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}}" Value="True">
<Setter Property="Border.Height" Value="100"/>
<Setter Property="Border.Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
<GradientStop Color="DarkGray" Offset="1"/>
<GradientStop Color="#FFE8E8E8"/>
<GradientStop Color="#FFBDBDBD" Offset="0.153"/>
<GradientStop Color="DarkGray" Offset="0.904"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="500"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="55"/>
</Grid.ColumnDefinitions>
<!--Pick number-->
<StackPanel Grid.Column="0" VerticalAlignment="Center" Orientation="Vertical">
<TextBlock Text="{Binding Path=FtgNamn}" FontWeight="Bold" FontSize="22pt" FontFamily="Calibri"/>
<TextBlock Text="{Binding Path=LevsAttBeskr}" FontSize="18pt" FontFamily="Calibri"/>
</StackPanel>
<!--Pick Quantity-->
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<TextBlock Text="{Binding Path=Antal}" FontSize="44pt" FontFamily="Calibri"/>
</StackPanel>
<!-- Checkbox-->
<StackPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center">
<ToggleButton Name="Check" Width="40" Height="40" Click="Check_Click" Tag="{Binding Path=Plocklista}">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="InnerBorder" Background="White" BorderBrush="Black" BorderThickness="1"/>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="InnerBorder" Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/Images/button_ok.png"/>
</Setter.Value>
</Setter>
<Setter TargetName="InnerBorder" Property="BorderThickness" Value="0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</StackPanel>
</Grid>
<Border BorderBrush="Darkgray" BorderThickness="0,0,1,0">
</Border>
<TextBlock Width="100" Text="{Binding Path=Quantity}" FontSize="44pt" FontFamily="Calibri"/>
<CheckBox Width="78"/>
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>