使用Copilot 詢問 C# MAUI 7.0 LISTVIEW 當項目被選擇 改變 背景顏色 和 文字顏色 [Create .NET MAUI ListView Example With Copilot]
使用Copilot 詢問 C# MAUI 7.0 LISTVIEW 當項目被選擇 改變 背景顏色 和 文字顏色 [Create .NET MAUI ListView Example With Copilot]
GITHUB: https://github.com/jash-git/Create-.NET-MAUI-ListView-Example-With-Copilot
01.直接問『C# MAUI 7.0 LISTVIEW 當項目被選擇 改變 背景顏色 和 文字顏色』 無法得到答案
02.所以我把對話過程也備份到『Copilot Ans』
■重點就是要他從頭開始自己做,雖然到最後它還是沒成功完成
■但是可以從它的解題過程發現一條新的做法
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="MauiApp1.MainPage"> <StackLayout> <Label Text="CollectionView Example" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" /> <CollectionView x:Name="MyCollectionView" SelectionMode="Single"> <CollectionView.ItemTemplate> <DataTemplate> <Grid> <Grid.Resources> <Style TargetType="Grid"> <Setter Property="VisualStateManager.VisualStateGroups"> <VisualStateGroupList> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal" /> <VisualState Name="Selected"> <VisualState.Setters> <Setter Property="BackgroundColor" Value="Blue" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateGroupList> </Setter> </Style> </Grid.Resources> <StackLayout> <Label Text="{Binding Name}" TextColor="Blue"> <Label.Triggers> <DataTrigger TargetType="Label" Binding="{Binding Source={RelativeSource AncestorType={x:Type Grid}}, Path=BackgroundColor}" Value="Blue"> <Setter Property="TextColor" Value="White" /> </DataTrigger> </Label.Triggers> </Label> <Label Text="{Binding Detail}" TextColor="Green"> <Label.Triggers> <DataTrigger TargetType="Label" Binding="{Binding Source={RelativeSource AncestorType={x:Type Grid}}, Path=BackgroundColor}" Value="Blue"> <Setter Property="TextColor" Value="White" /> </DataTrigger> </Label.Triggers> </Label> </StackLayout> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </StackLayout> </ContentPage>
MainPage.xaml.cs
using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime.CompilerServices; namespace MauiApp1 { public class Item { public string Name { get; set; } public string Detail { get; set; } } public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); var items = new List<Item> { new Item { Name = "Item 1", Detail = "This is item 1" }, new Item { Name = "Item 2", Detail = "This is item 2" }, new Item { Name = "Item 3", Detail = "This is item 3" } }; MyCollectionView.ItemsSource = items; } } }
One thought on “使用Copilot 詢問 C# MAUI 7.0 LISTVIEW 當項目被選擇 改變 背景顏色 和 文字顏色 [Create .NET MAUI ListView Example With Copilot]”
提高 AI 回答理工問題正確率的方法
李宏毅_生成式導論 2024_第3講:訓練不了人工智慧?你可以訓練你自己
~ https://www.youtube.com/watch?v=AVIKFXLCPY8&list=PLJV_el3uVTsPz6CTopeRp2L2t4aL_KgiI
~ https://hackmd.io/@shaoeChen/SyxNumm-0?utm_source=preview-mode&utm_medium=rec