Reputation: 62
How to change the textblock's color when when the ListViewItem is selected in the Windows 8.1 store app?
<ListView>
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding text}" Name="Mytxt" Foreground="Black"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Upvotes: 1
Views: 641
Reputation: 495
<ListView>
<ListViewItem Name="listViewItem1" Selected="listViewItem1_Selected">
<TextBlock Text="{Binding text}" Name="Mytxt"/>
</ListViewItem>
</ListView>
and
private void listViewItem1_Selected(object sender, RoutedEventArgs e)
{
Mytxt.Foreground = Brushes.Red;
Mytxt.Background = Brushes.Green;
}
Upvotes: 0
Reputation: 1193
Set ListViewItem Style and change the color when selected:
<Style x:Key="{x:Type ListViewItem}" TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid SnapsToDevicePixels="true" Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="buttonBackgroundShape"
Storyboard.TargetProperty="Opacity" To="1" Duration="0"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle Name="buttonBackgroundShape" Stretch="Fill" Opacity="0" Fill="Red" Height="50" SnapsToDevicePixels="True" />
<ContentPresenter x:Name="buttonText" Margin="30,0,30,0" TextBlock.FontSize="12pt" Content="{Binding Path=Name}" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Upvotes: 1
Reputation: 148
You can change the Color in the SelctionChanged Event :
Refer to the Link Below :
Upvotes: 0