|
I have defined a style as follows:
<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}"> .... </Style>
Now I want to bind that style to a listbox items...
This is the definition of the listbox: <ListBox Margin="0,0,0,0" x:Name="ListBox" IsSynchronizedWithCurrentItem="True" ItemTemplate="{DynamicResource photoTemplate_Small}" ItemsSource="{Binding Photos, Mode=Default, Source={StaticResource PhotosCollectionDS}}" Grid.Row="1" Grid.ColumnSpan="1" MinWidth="0" MinHeight="0" Grid.Column="1" BorderBrush="{x:Null}" d:LayoutOverrides="None" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="1" Background="{x:Null}" OverridesDefaultStyle="False" Style="{DynamicResource ListBoxStyle2}"> <ListBox.ItemsPanel > <ItemsPanelTemplate> <WrapPanel Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}" IsItemsHost="True" Cursor="Hand" /> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox>
I have tried replacing the ListboxStyle2 with ListBoxItemStyle1 and setting overridesDEfaultStyle to true, but then the application crashes....
My question is, how can I bind that ListBoxItemStyle1 to ListBox items....
P.S. here is the definition of the datatemplate bound to itemtemplate of the listbox: <DataTemplate x:Key="photoTemplate_Small"> <Grid Width="Auto" Height="Auto" x:Name="Grid" Margin="10,10,10,10" Opacity="1"> <Grid.ColumnDefinitions> <ColumnDefinition/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Border HorizontalAlignment="Left" Margin="0,0,0,0" Width="Auto" Background="White" x:Name="Border" BorderThickness="0,0,0,0" CornerRadius="8,8,8,8" Opacity="1"> <Image Source="{Binding Path=ThumbNailPhoto}" Width="100" Margin="5,5,5,5" x:Name="Image" Grid.Row="0" Height="Auto"/> </Border> </Grid> <DataTemplate.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}, AncestorLevel=1}, Path=IsSelected}" Value="True"> <Setter Property="Background" Value="Black" TargetName="Border"/> </DataTrigger> </DataTemplate.Triggers> </DataTemplate>
|