jack moseley
jack moseley

Reputation: 43

Changing font colour of textblock inside listview on selection

I'm trying to change the colour of a textblock that is a listview item when that listview item is selected. The data template of the listview item is as follows:

  <DataTemplate x:Key="DataTemplate">
    <Grid Height="47" VerticalAlignment="Stretch" Width="{Binding tbIng.Width}">
      <TextBlock x:Name="tbIng" FontFamily="{StaticResource Neutra2Text-Book}" FontSize="23" Text="50g of butter" HorizontalAlignment="Left" VerticalAlignment="Center" Padding="2"/>
    </Grid> 
  </DataTemplate>

I'm trying to use blend to find what i need to change, using the states window, but i cannot seem to find the textblock. If i right click on listview -> edit template -> edit current then i get the data template but cannot use the states window. This is a windows 8 application.

I want to do this in xaml, not the code

Upvotes: 0

Views: 614

Answers (3)

Mithila
Mithila

Reputation: 11

Add below mentioned code in your StandardStyles.xaml file and change the color you want:

<SolidColorBrush x:Key="ListViewItemSelectedForegroundThemeBrush" Color="Red" /> 

Upvotes: 1

Gnegno
Gnegno

Reputation: 366

From Blend, you can change the Generated Item Container (ItemContainerStyle) to override all the states and properties of the items of your ListView. To do so, use the upper menu as in picture:

enter image description here

and edit the states related to pressed,selected etc...

enter image description here

Upvotes: 0

Alex F
Alex F

Reputation: 3539

I can think of 2 paths:

  • You can use independent global/public variable and bind to it. So when ViewState changes so the DataTemplate and then TextBlock background will change color depending on this variable.
  • Pass the variable in Binding object itself just for that. For example if you bind to row in table - just add another column with value of TextBlock background and bind to it

Upvotes: 0

Related Questions