4
我面臨的問題是Xamarin表單和MVVM的初學者。我有tabbedpage,2頁在標籤下。這是代碼。
OnAppearing事件觸發兩次。帶標籤的頁面
問題是本地:ActiveOrderViewPage頁OnAppearing()事件射擊時兩次tabbedPage被OnAppearing負載條件下執行兩次代碼()事件。
請幫我找到爲什麼發生了這種情況?
這裏是代碼標籤頁 tabbedpage.xaml
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Orders">
<TabbedPage.Children>
<local:ActiveOrderViewPage />
<local:SavedOrderViewPage />
</TabbedPage.Children>
tabbedpage.xaml.cs
public partial class OrderTabViewPage : TabbedPage
{
public OrderViewModel ViewModel { get { return BindingContext as OrderViewModel; } }
public OrderTabViewPage()
{
InitializeComponent();
this.BindingContext = ViewModelLocator.OrderVModel;
}
public OrderTabViewPage(params object[] arg) : this()
{
if (arg != null)
{
ViewModel.AccountID = Convert.ToInt32(arg[0]);
}
}
這裏是爲了活躍的.cs
public partial class ActiveOrderViewPage : ContentPage
{
public OrderViewModel ViewModel { get { return BindingContext as OrderViewModel; } }
public ActiveOrderViewPage()
{
InitializeComponent();
this.BindingContext = ViewModelLocator.OrderVModel;
}
//public OrderViewPage() : this()
//{
// ViewModel.AccountID = accuntId;
//}
protected override void OnAppearing()
{
base.OnAppearing();
if (ViewModelLocator.OrderVModel.ActiveOrderItems == null || ViewModelLocator.OrderVModel.ActiveOrderItems.List.Count == 0)
{
ViewModelLocator.OrderVModel.ActiveOrderCommand.Execute(null);
}
}
在此先感謝...
停止
OnAppearing()
能否請你加什麼樣的代碼你已經嘗試..because沒有那個不能配置你的問題? – stylishCoder我已經爲這兩個頁面添加了代碼。請看看 – user2797910
具有相同的「問題」......你是否設法修復它? – MariusK