index > Windows Presentation Foundation ("Avalon") > Binding style to ListBox items

Binding style to ListBox items

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>

markovuksanovic
use ItemContainerStyle
lee d

[edit: Please refrain from posting full articles instead use the link.]

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/databindingadonet.asp

Grassgrass
reply 3

You can use google to search for other answers

 

More Articles

• Is there a RadioButtonList equivalent for Rich clients?
• databinding bug, or am i just expecting too much? - master/detail...
• Anyway to change WindowsFormsHost z-order to show other WPF contr...
• Can I simply cycling ScrollViewer?
• Get all bindings on a page?
• The name 'InitializeComponent' does not exist....
• Load image into richtext box
• Apply 2 or more styles to an element
• HitTest Custom Control
• Assigning EventTrigger.RoutedEvent to a Button
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• How to prevent TabControl from doing mul
• New XBAP and Code @ xamlXaml.com: Scroll
• How to implement interactive form modifi
• Not able to get "A Visual" fro
• custom control problems
• Cannot re-initialize ResourceDictionary
• FindResource Problem
• Unable to populate WPF Extender Control
• Not able to reference to custom control
• Sylin' a Panel's Navigation UI
• Setting my window to Bottommost, or Alwa
• Terminal Server and WPF
• ListBox not Displaying Feeds Help Please
• Pan
• xbap's can't upload images??

Hot Articles

• multiple animations within one EventTrig
• Synchronizing animation to video
• ObjectDataProvider and ConstructorParame
• Loaded event order reversed in RC1
• TiffBitmapEncoder issue
• Smart rendering of large amounts of geom
• Dwm thumbnails / Milcore / WPF
• Issue with WWF in VS2005 in Vista 5472
• What is "best practise" for da
• inline an image into XAML
• DataGrid
• Bug or Feature : Behavior of OneWay bind
• How to update DescendantBounds.X and Des
• how to apply Animation to image on click
• The size of Adorner nesting element

Recommend Articles

• When is Binding.ElementName non-NULL?
• How to use hardware rendering / video fl
• I want to do the input filter to TextBox.
• Animating a TextBlock's background
• GridView CellTemplate
• Possible bug: Hyperlink in a ListBox doe
• Dynamicly changing the staticresource to
• Intellisense Problem in XAML
• Keyboard.Focus() doesn't seem to be work
• BitmapImage is not raising the DownloadC
• Localization
• MediaElement in ListBox, selection, and
• HOw to add textbox columns in Datagrid v
• Please help with package signing
• Very slow grouping