【问题标题】:Xamarin forms picker item source not loadingXamarin 表单选择器项目源未加载
【发布时间】:2021-03-16 02:47:29
【问题描述】:

我创建了一个商店列表,将其添加到选择器中,但从视图中它没有加载。它显示了一个没有项目的选择器。

ViewModel代码如下

public List<string> Stores = new List<string>
        {
            "store 1",
            "store 2",
            "store 3"
        };

private int _selectedStoreIndex = -1;
        public int SelectedStoreIndex
        {
            get { return _selectedStoreIndex; }
            set
            {
                if (_selectedStoreIndex != value)
                {
                    _selectedStoreIndex = value;

                    UpdateStoreSelection();
                    OnPropertyChanged();
                }
            }
        }

Xaml 文件

<Picker ItemsSource="{Binding Stores}" SelectedIndex="{Binding SelectedStoreIndex}"/>

【问题讨论】:

  • 您好,您可以查看Lifecycle methods 以在OnStart/OnSleep/OnResume 中添加计时器来计算运行时间。

标签: xamarin xamarin.forms picker


【解决方案1】:

当进行冷启动时,OnStart 中的 App.xaml.cs 方法将被调用。然后,您可以使用Secure Storage / Preference 将密钥保存在每个平台的本地存储中,然后只需使用 DateTime.Now 来计算差异。并且当应用程序被销毁并重新启动时,OnStart 将被再次调用并重置密钥。

【讨论】:

    【解决方案2】:

    您只需要获取进程的开始时间,以及当前时间。

    var startime = Process.GetCurrentProcess().StartTime;
    var currenttime = DateTime.Now;
    var runningtime = (nowtime - startime).TotalSeconds;
            
    

    【讨论】:

      猜你喜欢
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      • 2021-10-23
      • 1970-01-01
      • 2017-03-15
      相关资源
      最近更新 更多