0
我有一個簡單的帶有3個選項卡的ActionBar。當點擊一個標籤時,該片段被充氣並顯示視圖。正在點擊事件的標籤是使用事件觸發的。最初,第一個片段被誇大了,但其他片段被點擊後會迴應並膨脹。當選中標籤時,ICommand並不總是觸發
如果我將被觸發的事件更改爲ICommand
,則只有最後一個片段被充氣,然後如果我點擊第一個選項卡,則最後一個選項卡將被充氣。從來沒有第二。
我的代碼是這樣的
ICommand TabClicked
{
get
{
return new RelayCommand(() =>
{
tab.TabSelected += (object sender, ActionBar.TabEventArgs e) => TabOnTabSelected(sender, e);
});
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
fragments.Add(new TODFragment());
fragments.Add(new ConditionsFragment());
fragments.Add(new ResultsFragment());
AddTabToActionBar("Time", Resource.Drawable.crucifix_colour);
AddTabToActionBar("Conditions", Resource.Drawable.weather_colour);
AddTabToActionBar("Results", Resource.Drawable.tod_colour);
}
void AddTabToActionBar(string text, int iconResourceId)
{
tab = ActionBar.NewTab().SetTag(text).SetText(text).SetIcon(iconResourceId);
/* uncomment and comment out one of the two below to see the difference in operation */
tab.TabSelected += TabOnTabSelected;
//tab.SetCommand<ActionBar.TabEventArgs>("TabSelected", TabClicked);
ActionBar.AddTab(tab);
}
void TabOnTabSelected(object sender, ActionBar.TabEventArgs tabEventArgs)
{
var tabNo = sender as ActionBar.Tab;
var frag = fragments[tabNo.Position];
tabEventArgs.FragmentTransaction.Replace(Resource.Id.frameLayout1, frag);
}
我失去了在個ICommand和事件之間的區別就在這裏一些基本的東西還是別的東西?
我使用Xam.Android和MVVMLight