Change foreground color of listviewitem in xaml

I am developing a Windows Phone 8.1 Application in C # / XAML.

I have a listview whose background is set to white. As a result, you don't see the list items because the foreground is also white. I would like to change this to a different color. However, when an element is selected, I would like to change the foreground color to white, since when an element is selected, the background of that element changes color (yellow), allowing the user to see the color white.

I have uploaded my code to PasteBin:

MainPage.xaml (actual page): http://pastebin.com/R9DG9D2J

App.xaml: http://pastebin.com/21qQxHge

In App.xaml, I have overridden the brush ListViewItemSelectedBackgroundThemeBrush

so when an element is selected it has a yellow background instead of the default cyan. However, I am unable to change the foreground color of the element. I don't want to hard-code the foreground color in the textbox in the DataTemplate of the ListViewItem as if I did, then the color does not change to white when the item is selected.

How should I do it?

+3


source to share


1 answer


Try to set the foreground color of the ListViewItem using the Style trigger, check the IsSelected condition is true and then change the Foreground property to whatever color you want when the item is selected, thus only the selected item of the ListView will change



<Style TargetType="{x:Type ListViewItem}">
    <Style.Triggers>
        <Trigger Property="ListViewItem.IsSelected" Value="True">
            <Setter Property="Foreground" Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

      

0


source







All Articles