我有一个ListView,当我将鼠标悬停在每个ListViewItem上时,我想在其中指定一个Style 这是我的风格:Details.xaml:
<ListView x:Name="listmee">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimation Duration="0" To="#d9d7ec" Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="listItem1" />
<ColorAnimation Duration="0" To="Black" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Content1" />
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ColorAnimation Duration="0" To="#d9d7ec" Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="listItem1" />
<ColorAnimation Duration="0" To="Black" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="Content1" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups>
<Grid>
<Rectangle x:Name="listItem1" Stroke="Transparent" Fill="Transparent" />
<ContentPresenter x:Name="Content1"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
<TextBlock x:Name="day" Text="{Binding Path=nom_jour}" Foreground="Gray" ></TextBlock>
</StackPanel>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<TextBlock x:Name="hour_deb" Text="{Binding Path=deb_jour}" Foreground="Gray"></TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate >
</ListView>
问题是我的代码在悬停时更改ListviewItem的背景颜色但是当悬停时文本颜色不会改变 请问我该怎么解决它 谢谢你的帮助
更新: 我使用UserControl在我的ListView上应用Style,如下所示:
Details.xaml:
<Page.Resources>
<DataTemplate x:Key="ListViewTemplate">
<local:ListViewTemplate Content="{Binding}"/>
</DataTemplate>
</Page.Resources>
<ListView x:Name="listmee" ItemTemplate="{StaticResource ListViewTemplate}">
<ListView.ItemContainerStyle>
<!--I have put here the Style-->
</ListView.ItemContainerStyle>
</ListView>
Details.xaml.cs:
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
getDaysHours();
}
private async void getDaysHours()
{
UriString2 = "webService;
var http = new HttpClient();
http.MaxResponseContentBufferSize = Int32.MaxValue;
var response = await http.GetStringAsync(UriString2);
var rootObject1 = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
listmee.ItemsSource = rootObject1.horaire_local;
}
ListViewTemplate.xaml :( UserControl文件)
<StackPanel Orientation="Horizontal">
<StackPanel HorizontalAlignment="Left">
<TextBlock x:Name="day" Text="{Binding Path=nom_jour}"/>
</StackPanel>
<StackPanel HorizontalAlignment="Right">
<TextBlock x:Name="hour_deb" Text="{Binding Path=deb_jour}" />
<TextBlock x:Name="hour_fin" Text="{Binding Path=fin_jour}"/>
</StackPanel>
</StackPanel>
当我加载页面时,我得到一个空列表,在我的代码中想念我?