在网格中搜索处理程序

问题描述 投票:0回答:1

我想知道是否可以在 <Grid> 中拥有 maui

搜索处理程序
。我不想将其放在工具栏中,而是希望将其功能作为输入表单的一部分,在其中我可以输入一些字母,它会显示包含带有数据绑定的字母的内容。我知道有“选择器”,但它没有输入栏,当数据很多时,你需要从长列表中查找你想要的东西是没有用的。

目前有:

<Shell.SearchHandler>
   <local: ProductSearchHandler ...>
</Shell.SearchHandler>

希望有类似的东西

<Grid>
   <Label Text="Product">
   <local: ProductSearchHandler ...>
</Grid>

我从第三方网站找到了 ComboBox,但我想尽可能使用 maui 内置功能。

xaml controller maui
1个回答
0
投票

从文档.NET MAUI Shell搜索,我们可以发现

SearchHandler
是设计在页面顶部添加的。

而且它是添加在

ContentPage
的内侧。如果你把它放在不同的位置,它就不会显示。

如下:

<ContentPage ...
             xmlns:controls="clr-namespace:Xaminals.Controls">
    <Shell.SearchHandler>
        <controls:AnimalSearchHandler 
                                      ... />
    </Shell.SearchHandler>
    ...
</ContentPage>

因此,您不能在

Shell.SearchHandler
内使用
Grid

但作为解决方法,您可以使用

SearchBar
代替。

<?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"
             x:Class="MauiListViewMVVMApp.PrinterSettingsPage"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
             xmlns:appModel="clr-namespace:MauiListViewMVVMApp.Models"
             xmlns:appVM="clr-namespace:MauiListViewMVVMApp.ViewModels"
             Title="PrinterSettingsPage">
        

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="100" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Label Text="Product" >
        <SearchBar Placeholder="Search items..."  Grid.Row="1"/>



    </Grid>
</ContentPage>

欲了解更多信息,您可以查看:SearchBar

© www.soinside.com 2019 - 2024. All rights reserved.