Remove()
またはしようとしていClear()
ToolbarItems
ます。ToolbarItem
MainPage.csで作成しているコードは次のとおりです
public partial class MainPage : MasterDetailPage
{
public ToolbarItem cCounter = new ToolbarItem() { Icon = "picture.png" };
public ToolbarItem pPo = new ToolbarItem() { Text = "-" };
public MainPage()
{
InitializeComponent();
if (Device.OS == TargetPlatform.iOS)
{
provider.Clicked += iOS_Ppo_Clicked;
ToolbarItems.Add(cCounter);
ToolbarItems.Add(pPo);
}
}
private void iOS_Ppo_Clicked(object sender, EventArgs e)
{
OpenWindow();
}
public async void OpenWindow()
{
if (await Common.WindowComands.CanOpenWindow<PPoPage>(Detail))
{
page = new PPoPage(Page3.Allproviders);
this.ToolbarItems.Clear(); // here I am getting error:Index was outside the bounds of the array
page.OnSelected += Page_OnSelected;
await Detail.Navigation.PushAsync(page, false);
}
}
}
編集: 別のページが開いて動作することを初期化するメソッド
this.ToolbarItems.Clear();
に含めたとき!OpenWindow
すべてのツールバー項目を消去しますが、残念ながら次のエラーが表示されます:System.IndexOutOfRangeException: Index was outside the bounds of the array.
ご覧のとおり、この項目は iOS でのみ表示されなくなります。Remove()
これらをしたい私のページクラスは次のToolbarItems
とおりです。
public partial class PPoPage : ContentPage
{
public MainPage main { get; set; }
private List<PPo> Pro;
public PPoPage(List<PPo> po)
{
InitializeComponent();
if (Device.OS == TargetPlatform.iOS)
{
Pro = po;
CreateLayout();
// HERE I WANT TO REMOVE TOOLBARITEMS FOR THIS PAGE
this.ToolbarItem.Remove(main.cCounter); // here there is error
this.ToolbarItems.Clear(); // this also doesn't work, because toolbar items still exist after this initialization.
}
}
}
このクラスでは、両方のアプローチを試しましたが、どれもうまくいきませんでした。回答または提案ありがとうございます。