<CollectionView x:Name="nList" SelectionMode="Single" VerticalScrollBarVisibility="Always" SelectionChanged="OnMakingSelection" >
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<SwipeView>
<SwipeView.RightItems>
<SwipeItem Text="Delete" BackgroundColor="Red" Invoked="Delete_Btn" >
</SwipeItem>
</SwipeView.RightItems>
<StackLayout BackgroundColor="AntiqueWhite">
<Label Text="{Binding UserNotes}" TextColor="Black" FontFamily="PK" FontAttributes="Bold" FontSize="33" HorizontalOptions="Center"/>
<Label x:Name="loclabel" Text= "{Binding Location}" FontAttributes="Bold" TextColor="Black" HorizontalOptions="Center" />
<Button x:Name="mapbtnnn" Text="Open in Maps" FontFamily="PF" Clicked="Button_Clicked_Map" BackgroundColor="PowderBlue" CornerRadius="40" HorizontalOptions="Center"></Button>
<Image x:Name="Image" Source="{Binding Pic}" HeightRequest="90" ></Image>
<Label Text="*END OF NOTE*" FontAttributes="Bold" TextColor="Black" HorizontalOptions="Center"/>
</StackLayout>
</SwipeView>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
想要在選擇時為所選專案添加顏色。
任何提示,
我在網上嘗試了很多步驟,但似乎都沒有奏效。
目前選擇時不顯示顏色
uj5u.com熱心網友回復:
想要在選中時為選中的專案添加顏色。
您可以使用visual-state-manager更改所選專案的顏色,將滑動背景顏色設定為白色,并添加 VisualStateManager.VisualStateGroups 進行滑動,如下所示:
<CollectionView x:Name="nList" SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<SwipeView BackgroundColor="White">
<SwipeView.RightItems>
<SwipeItem Text="Delete" BackgroundColor="Red" >
</SwipeItem>
</SwipeView.RightItems>
<StackLayout Padding="5" Orientation="Vertical">
<Label LineBreakMode="WordWrap" Text="{Binding Name}" />
</StackLayout>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal" />
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Yellow" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
后面的代碼:
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
nList.ItemsSource = new List<Contact>
{
new Contact("JP Morgan"),
new Contact("Andrew Carnegie"),
new Contact("Steve Jobs")
};
}
}
public class Contact
{
public string Name { get; set; }
public Contact(string name)
{
Name = name;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/470501.html
標籤:xamarin xamarin.forms xamarin.android 集合视图
