无法将 TextBlock 前景置于黑色 UWP Color Foreground ListView
Can't put the TextBlock foreground in black UWP Color Foreground ListView
如果左键单击,我想将 TextBlock 前景设置为灰色,如果右键单击,我想将 TextBlock 前景设置为黑色。实际上程序不是在右键单击时执行,而是在左键单击时执行。它有什么问题?
private void SelectList1_LeftTapped(object sender, ItemClickEventArgs e)
{
dynamic clickedItem = e.ClickedItem;
ListViewItem item = SelectList1.ContainerFromItem(clickedItem) as ListViewItem;
item.Foreground = new SolidColorBrush(Colors.Gray);
Article selectArticle = item.Content as Article;
WebView1.Source = new System.Uri(selectArticle.article_link);
DataAccess.ArticleIsRead(selectArticle.article_id);
}
private void SelectList1_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
ListViewItemPresenter clickedItem = e.OriginalSource as ListViewItemPresenter;
Article selectArticle = clickedItem.DataContext as Article;
ListViewItem item = SelectList1.ContainerFromItem(selectArticle) as ListViewItem;
item.Foreground = new SolidColorBrush(Colors.Black);
item.Background = new SolidColorBrush(Colors.Black);
string selectArticleId = selectArticle.article_id;
DataAccess.ArticleNotRead(selectArticleId);
}
我通过使用 ListView 设置 IsItemClickEnabled="True"
来测试我的代码,左键单击和右键单击都可以正常工作。
<Border Grid.Column="1">
<ListView x:Name="SelectList1" ItemsSource="{x:Bind allArticleList}" IsItemClickEnabled="True" ItemClick="SelectList1_LeftTapped" RightTapped="SelectList1_RightTapped" ItemTemplate="{StaticResource ArticleDataTemplate}" ItemContainerStyleSelector="{StaticResource ArticleStyleSelector}">
</ListView>
</Border>
如果左键单击,我想将 TextBlock 前景设置为灰色,如果右键单击,我想将 TextBlock 前景设置为黑色。实际上程序不是在右键单击时执行,而是在左键单击时执行。它有什么问题?
private void SelectList1_LeftTapped(object sender, ItemClickEventArgs e)
{
dynamic clickedItem = e.ClickedItem;
ListViewItem item = SelectList1.ContainerFromItem(clickedItem) as ListViewItem;
item.Foreground = new SolidColorBrush(Colors.Gray);
Article selectArticle = item.Content as Article;
WebView1.Source = new System.Uri(selectArticle.article_link);
DataAccess.ArticleIsRead(selectArticle.article_id);
}
private void SelectList1_RightTapped(object sender, RightTappedRoutedEventArgs e)
{
ListViewItemPresenter clickedItem = e.OriginalSource as ListViewItemPresenter;
Article selectArticle = clickedItem.DataContext as Article;
ListViewItem item = SelectList1.ContainerFromItem(selectArticle) as ListViewItem;
item.Foreground = new SolidColorBrush(Colors.Black);
item.Background = new SolidColorBrush(Colors.Black);
string selectArticleId = selectArticle.article_id;
DataAccess.ArticleNotRead(selectArticleId);
}
我通过使用 ListView 设置 IsItemClickEnabled="True"
来测试我的代码,左键单击和右键单击都可以正常工作。
<Border Grid.Column="1">
<ListView x:Name="SelectList1" ItemsSource="{x:Bind allArticleList}" IsItemClickEnabled="True" ItemClick="SelectList1_LeftTapped" RightTapped="SelectList1_RightTapped" ItemTemplate="{StaticResource ArticleDataTemplate}" ItemContainerStyleSelector="{StaticResource ArticleStyleSelector}">
</ListView>
</Border>