Hello,
Picker native to Maui does not currently provide content that allows you to modify the pop-up part. For this need, you can implement a fully custom Picker by combining Entry and Popup.
Please refer to the following documentation and sample code:
Item:
public class Item
{
public string Name { get; set; }
public bool IsEnabled { get; set; }
}
Entry:
<Entry IsReadOnly="True" x:Name="test_entry">
<Entry.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Entry.GestureRecognizers>
</Entry>
private async void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
var popup = new NewPage1();
// The data returned by the Popup is taken as the result
var result = await this.ShowPopupAsync(popup,CancellationToken.None);
if (result is Item)
{
var item = (Item)result;
test_entry.Text = item.Name;
}
}
Popup:
<toolkit:Popup xmlns="
http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="
http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp10"
xmlns:toolkit="
http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="MauiApp10.NewPage1">
<toolkit:Popup.BindingContext>
<local:PopupViewModel/>
</toolkit:Popup.BindingContext>
<VerticalStackLayout>
<ListView x:Name="ListView" ItemsSource="{Binding Items}" SelectionMode="Single" ItemSelected="ListView_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Name}" IsEnabled="{Binding IsEnabled}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</VerticalStackLayout>
</toolkit:Popup>
private async void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as Item;
// If the selected item is Not Enable, a alert window will be displayed.
if (item.IsEnabled) {
await this.CloseAsync(e.SelectedItem);
}
else
{
await App.Current.MainPage.DisplayAlert("Alert", "Items in a non-Enable state cannot be selected.", "OK");
}
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.