未加载Xamarin表单选取器项目源

km0tfn4u  于 2022-12-07  发布在  其他
关注(0)|答案(3)|浏览(129)

我已经创建了一个商店列表,并将其添加到一个选择器中,但从视图中无法加载。它显示的是一个没有项目的选择器。
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}"/>
hpxqektj

hpxqektj1#

当冷启动时,OnStart中的OnStart方法被调用。然后你可以使用Secure Storage/Preference在每个平台的本地存储中保存一个密钥,然后只使用DateTime。现在只计算差值。当应用被销毁并重新启动时,OnStart将被再次调用,只重置密钥。

kpbpu008

kpbpu0082#

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

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

mpbci0fu3#

我已经修复了从ViewModel更新数据的问题

相关问题