I have a ListBox in WPF Window and an image + text block as item. I am trying to set the foreground of the text block via a property (i.e. ItemForegroundColor).
ItemForegroundColor is a property in ViewModel of type SolidColorBrush, not of a property of item in AppInfoCollection.
The foreground color is not set to the intended color, rather it stays black.
<ListBox Name="lbInfoGridView"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="False"
Background="{Binding Path=BackgroundColor}"
ItemsSource="{Binding AppInfoCollection}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5"
VerticalAlignment="Stretch"
HorizontalAlignment="Center"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="spItemInfo"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="0 0 0 0"
Background="{Binding Path=BackgroundColor}">
<Image Name="imgProfile"
Margin="0 0 0 0"
Width="50" Height="100"
Source="{Binding ProfileImage, Converter={StaticResource binaryConverter}}"></Image>
<TextBlock Name="tbName"
Margin="10 0 0 0"
Text="{Binding Name}"
Foreground="{Binding Path=ItemForegroundColor}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I thoughtvthe issue might be ListBox.ItemTemplate not being able to refer to ViewModel level. Hence I have tried using something like below.
Foreground="{Binding Path=MovieActorNameForegroundColor, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}} }"
Also tried ItemContainerStyle approach as mentioned in https://wildermuth.com/2007/04/17/Changing_the_Selected_Style_of_ListBox_s_in_XAML
Advice is much appreciated.