<syncfusion:SfListView x:Name="ListView1" ItemsSource="{Binding NearProductsList}" SelectionMode="Single" ItemTapped="Item_Tapped" Orientation="Horizontal" ItemSpacing="0,0,0,0" AutoFitMode="None" ItemSize="200" HeightRequest="150" IsScrollBarVisible="False">
<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Source = "NoImage.png" HorizontalOptions = "Center" VerticalOptions = "Start" />
<Label Grid.Row="1" LineBreakMode="NoWrap" Text="{Binding ProductName}" TextColor="#292a60" FontSize="10" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Grid.Row="2" LineBreakMode="NoWrap" Text="{Binding ProductPriceBoleto, StringFormat='A partir de R${0}'}" TextColor="#292a60" FontSize="10" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
</Grid>
</DataTemplate>
</syncfusion:SfListView.ItemTemplate>
</syncfusion:SfListView>
The code Behind:
public Home()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
Padding = new Thickness(0, 10, 0, 0);
Color Amarelo = Color.FromRgb(212, 217, 75);
Color Azul = Color.FromRgb(41, 42, 96);
BackgroundColor = Azul;
}
private async void Item_Tapped(object sender, ItemTappedEventArgs e)
{
var SearchNear = ListView1.SelectedItem as NearProducts; //As ItemTapped avoid item selection, The ListView1.SelectItem always comes null. NearProducts come from model class.
Settings.SelectedProduct = SearchNear.BusinessName; //Error occurs here as Settings.SelectedProduct are string.
await Navigation.PushAsync(new ProductListPage(), false);
}
Thanks in advance.
Daniel.
|
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
listView.SelectionChanged += ListView_SelectionChanged;
}
private void ListView_SelectionChanged(object sender, ItemSelectionChangedEventArgs e)
{
var newPage = new NewPage();
newPage.BindingContext = (sender as SfListView).SelectedItems;
Navigation.PushAsync(newPage);
}
} |