I have to put an expander on every circle (Where you can see the abbreviation of the car)
I have my ListViewPage Xaml
<ContentPage.Content>
<CollectionView
x:Name="CarsList"
ItemsSource="{Binding Cars}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<SwipeView>
<SwipeView.RightItems>
<SwipeItems Mode="Execute">
<SwipeItem
BackgroundColor="Red"
Command="{Binding Source={x:Reference ListPage}, Path=BindingContext.DeleteCommand}"
CommandParameter="{Binding .}"
Text="Delete" />
</SwipeItems>
</SwipeView.RightItems>
<local:CarView
Padding="0,10,0,0"
xct:TouchEffect.AnimationEasing="CubicInOut"
xct:TouchEffect.Command="{Binding Source={x:Reference ListPage}, Path=BindingContext.PressedCommand}"
xct:TouchEffect.CommandParameter="{Binding .}"
xct:TouchEffect.LongPressCommand="{Binding Source={x:Reference ListPage}, Path=BindingContext.LongPressedCommand}"
xct:TouchEffect.LongPressCommandParameter="{Binding .}"
xct:TouchEffect.NativeAnimation="True"
xct:TouchEffect.PressedScale="0.8" />
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage.Content>
</ContentPage>
And I have two more views, the CarPageView
<ContentView.Content>
<Grid>
<Frame Margin="5,15,5,5"
BorderColor="LightGray"
CornerRadius="5"
HasShadow="False">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid IsVisible="{Binding IsExpanded, Source={x:Reference _carView}}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label HorizontalOptions="End"
Text="{Binding Notes}"
TextColor="Gray" />
<Label Grid.Row="1" Text="{Binding Description}" />
</Grid>
</Grid>
</Frame>
<StackLayout Margin="20,0,0,0"
BackgroundColor="White"
HorizontalOptions="Start"
Orientation="Horizontal"
VerticalOptions="Start">
<local:CarCircleView Margin="7,0,0,0"
Command="{Binding ToggleCollapseCommand, Source={x:Reference _carView}}"
HeightRequest="30"
HorizontalOptions="Start"
VerticalOptions="Start"
WidthRequest="30" />
<Label Margin="0,0,7,0"
FontAttributes="Bold"
Text="{Binding Name}"
VerticalTextAlignment="Center" />
</StackLayout>
</Grid>
</ContentView.Content>
And the circleView
<ContentView.Content>
<Frame
x:Name="_borderOuter"
Padding="1"
BackgroundColor="{Binding Color}"
BorderColor="{Binding Color}"
HasShadow="False">
<Frame
x:Name="_borderInner"
Padding="5"
BorderColor="{Binding Color}"
HasShadow="False">
<Label
Margin="1,-1,0,0"
FontAttributes="Bold"
HorizontalOptions="Center"
HorizontalTextAlignment="Center"
Text="{Binding Abbreviation}"
VerticalOptions="Center"
VerticalTextAlignment="Center" />
</Frame>
</Frame>
</ContentView.Content>
VM
public Command<Car> PressedCommand
{
get; set;
}
public Command<Car> LongPressedCommand
{
get; set;
}
public Command<Car> DeleteCommand
{
get; set;
}
public SampleViewModel()
{
DeleteCommand = new Command<Car>(DeleteAction);
LongPressedCommand = new Command<Car>(LongPressedAction);
PressedCommand = new Command<Car>(PressAction);
GridSpan = Device.Idiom == TargetIdiom.Phone ? 1 : 2;
BuildCars();
}
private void DeleteAction(Car obj)
{
Cars.Remove(obj);
}
private async void PressAction(Car obj)
{
if (obj != null && obj.Make == CarMake.Mercedes)
{
var MercedesView = new MecedesSpecificView()
{
BindingContext = new MecedesSpecificViewModel(obj)
};
await Application.Current.MainPage.Navigation.PushAsync(MercedesView);
}
else
{
var DetailsPage = new ListViewDetailPage
{
BindingContext = new ListViewDetailPageViewModel(obj)
};
await Application.Current.MainPage.Navigation.PushAsync(DetailsPage);
}
}
private async void LongPressedAction(Car obj)
{
var ans = await Application.Current.MainPage.DisplayAlert("Warning", "do you want to delete?", "OK", "Cancel");
if (ans)
{
Cars.Remove(obj);
}
}
private int _gridSpan;
public int GridSpan
{
get => _gridSpan;
set => SetProperty(ref _gridSpan, value);
}
private void BuildCars()
{
Cars = new ObservableCollection<Car>
{
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Notes = "test car", Description = "Some description", Color = Color.Black },
new Car { Abbreviation = "BMW", Make=CarMake.BMW, Name = "X5", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 10)), Color = Color.Purple },
new Car { Abbreviation = "M", Make=CarMake.Mercedes, Name = "AMG C Class", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 5)), Color = Color.CornflowerBlue},
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.Brown },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 3)), Color = Color.Orange },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.DarkBlue },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 7)), Color = Color.DarkOrange },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.OrangeRed },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 4)), Color = Color.Violet},
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 2)), Color = Color.DarkSalmon },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.Green },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 6)), Color = Color.GreenYellow},
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 3)), Color = Color.LawnGreen},
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.SkyBlue },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = string.Concat(Enumerable.Repeat($"Some description {Environment.NewLine}", 5)), Color = Color.LightCyan },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.PaleTurquoise },
new Car { Abbreviation = "VW", Make=CarMake.VolksWagen, Name = "Polo", Description = "Some description", Color = Color.Purple },
};
}
private ObservableCollection<Car> _cars;
public ObservableCollection<Car> Cars
{
get
{
return _cars;
}
set
{
SetProperty(ref _cars, value);
}
}
}
What I do not understand is, that I already tried to use the xamarin community expander on the CirclePage, but for some reason, it did not work.
This is the Instruccion that I got
- Using the ListView Page:
- add an expand/collapse animation when tapping the circle
I tried to add the expander, but I think that because of the TouchEffect on every cell, it doesn't work.
So how can I have the two o them play nice with each other, I want to maintain the ability to navigate, but I also want to be able to expand when I press the circle
https://reccloud.com/u/bg8pvw1 // this is how it is right now
Oh by the way I was able to use a collectonView after all, that is wwht I am making this update