3つのタブが付いた簡単なActionBarがあります。タブをクリックすると、フラグメントが膨張し、ビューが表示されます。タブをクリックするイベントは、イベントを使用して発生します。最初は、最初の断片は膨張しますが、他の断片はクリックすると反応して膨張します。タブが選択されたときにICommandが必ずしも起動しない
イベントを起動する時刻をICommand
に変更すると、最後のフラグメントのみが展開され、最初のタブをクリックすると最後の部分が膨張します。決して2番目。
私のコードは、私がICommandsとイベントとの差がここに根本的な何かが欠けているか、それが何か他のものである。この
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);
}
アムのですか?私はXam.AndroidとMVVMLight