<ListBox x:Name="noteListBox"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" Foreground="#FF329BD6" Margin="0,24,0,85">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="noteTitle"
FontSize="40"
Text="{Binding Titolo}"
Tag="{Binding FileName}"
Foreground="#FF45B1EE" Tap="apriNota" Margin="5,0,0,0" />
<TextBlock x:Name="noteDateCreated"
Text="{Binding DateCreated}"
Margin="10,0,0,10" Foreground="#FF60ADD8" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I need to dynamically change the Foreground color of those two TextBlocks inside the StackPanel. The problem is that they don’t seem to be accessible from my C# code, suppose because they’re in that StackPanel.
So basically this is what I need to do:
noteTitle.Foreground = new SolidColorBrush(Color.FromArgb(255, 50, 155, 214));
But I can’t even find noteTitle in my C# code… How can I fix this?
Thank you!
I would suggest using value converter for such purposes. I assume foreground value depends on a state of object whcih ahs proeprties
FileName,DateCreatedyou bind to, so just use this object as converetr parameter and in converter do main calculation to decide which Foreground should be returned for this particular item.