I have a listbox with many listboxitems inside. those items only contain text elements. What I want to do is change the text style (and maybe the background colour as well) for a single listboxitem in c# code (as I need to apply conditions). how would I go about that?
XAML:
<ListBox x:Name="todoList" Margin="5, 5, 5, 5" Grid.Row="1" SelectionChanged="todoList_SelectionChanged"/>
I fill the listbox by parsing a file and then adding items to the listbox.
Subclassing the ItemControlStyleSelector did not seem to work in my case as you cannot overwrite the SelectStyle function in the UWP case.
I am able to apply a style to the WHOLE ListBox (all ListBoxItems) by:
Style st = new Style();
st.TargetType = typeof(ListBoxItem);
st.Setters.Add(new Setter(ListBoxItem.BackgroundProperty, "Blue"));
todoList.ItemContainerStyle = st;
What would a good approach be to change only one item's style in code? The goal is to apply some styling to certain items after the user pressed a specific button / key on the keyboard.
thanks!