You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI中使用GoToAsync传递导航参数后ListView未加载数据的问题

MAUI中使用GoToAsync传递导航参数后ListView未加载数据的问题

Hey,我看了你的代码,问题主要出在QueryProperty的使用方式和UI数据更新逻辑上,给你几个关键的修复点:

1. QueryProperty需要绑定公共属性,而非私有字段

你当前的FireList是私有字段,[QueryProperty]特性无法正确设置私有成员的值,而且也没有触发UI更新的通知机制。你需要把它改成带INotifyPropertyChanged支持的公共属性:

using System.ComponentModel;
using System.Runtime.CompilerServices;

[QueryProperty(nameof(FireList), "firelist")]
public partial class ListPage : ContentPage, INotifyPropertyChanged
{
    private List<TIR> _fireList = new List<TIR>();
    
    // 公共属性,供QueryProperty和UI绑定使用
    public List<TIR> FireList
    {
        get => _fireList;
        set
        {
            if (_fireList != value)
            {
                _fireList = value;
                // 触发属性变化通知,告诉UI更新数据
                OnPropertyChanged();
                // 如果你不用数据绑定,也可以在这里直接更新ListView的ItemsSource
                // LST01_LP_TIR.ItemsSource = _fireList;
            }
        }
    }

    // 实现INotifyPropertyChanged接口
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public ListPage()
    {
        InitializeComponent();
        BindingContext = this;
        // 这里不用提前设置ItemsSource了,属性更新时会自动处理
        // LST01_LP_TIR.ItemsSource = FireList;
    }
}

2. 确保ListView的ItemsSource正确绑定

如果选择用数据绑定的方式,需要在ListPage的XAML里给ListView指定绑定路径:

<ListView x:Name="LST01_LP_TIR" ItemsSource="{Binding FireList}">
    <!-- 这里添加你的ItemTemplate,比如显示TIR的属性 -->
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding YourTIRPropertyName}" />
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

注意:YourTIRPropertyName要替换成你TIR类中实际的公共属性名,否则数据也无法显示。

3. 检查导航路径(可选,确保路由匹配)

你的导航代码用了//P_List绝对路由,这本身没问题,但要确认TabBar中LISTE标签的Route确实是P_List,和你代码里的路径一致,这点你当前的代码是匹配的,所以这个不是主要问题。

额外验证点

  • 确认NewOrder.LIST_TIR确实包含有效数据(你说已经确认了,这步可以跳过)
  • 确认TIR类的属性都是公共可访问的,否则即使数据传过去了,ListView也无法读取到属性值

按照上面的步骤修改后,当你通过GoToAsync传递参数时,FireList属性会被正确设置,同时触发UI更新,ListView就能显示数据了。

备注:内容来源于stack exchange,提问作者Xeno6x

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 06:14:34