I trying to show data in dynamically created pickers. This is my code.This data is loading in viewmodel but its not visible in my picker. When user enter No Of Nights as 2 then 2 pickers are generating. I can’t found any issues here data also loading, Only issue is not visible. Anyone have idea to fix this. Please help.
NewPostPage.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"
xmlns:ur="http://schemas.enisn-projects.io/dotnet/maui/uraniumui/material"
x:Class="DriveMeSL.View.NewPostPage"
xmlns:vm="clr-namespace:DriveMeSL.ViewModels"
NavigationPage.HasNavigationBar="True"
Title="New Post">
<ContentPage.BindingContext>
<vm:NewPostViewModel />
</ContentPage.BindingContext>
<ScrollView>
<VerticalStackLayout VerticalOptions="Center"
Margin="20,0,20,0"
Spacing="20">
<Label Text="Create Post"
TextColor="#101010"
FontSize="Large"
HorizontalOptions="Center"/>
<ur:DatePickerField x:Name="EntDate"
Title="Date" />
<ur:TimePickerField x:Name="EntTime"
Title="Pick a Time" />
<StackLayout Padding="20">
<Label Text="Enter Number of Nights:" />
<Entry Text="{Binding NoOfNights, Mode=TwoWay}" Keyboard="Numeric" />
<CollectionView ItemsSource="{Binding NightLocations}">
<CollectionView.ItemTemplate>
<DataTemplate>
<ur:PickerField Title="Enter location"
ItemsSource="{Binding Locations}"
ItemDisplayBinding="{Binding LocationName}"
SelectedItem="{Binding SelectedLocation}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
<Button Text="Save" Command="{Binding SaveCommand}" />
<Button x:Name="BtnNewPost" StyleClass="FilledButton" Text="Add Post" Clicked="BtnNewPost_Clicked" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
NewPostPage.xaml.cs
public partial class NewPostPage : ContentPage
{
private NewPostViewModel viewModel;
public NewPostPage()
{
InitializeComponent();
viewModel = new NewPostViewModel();
BindingContext = viewModel;
// Call the async method to load locations
_ = LoadLocationsAsync();
}
private async Task LoadLocationsAsync()
{
await viewModel.LoadLocationsAsync();
}
}
}