Reputation: 43
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
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
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:
and edit the states related to pressed,selected etc...
Upvotes: 0
Reputation: 3539
I can think of 2 paths:
ViewState
changes so the DataTemplate
and then TextBlock
background will change color depending on this variable.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 itUpvotes: 0