C# 如何检测Xamarin表单选项卡式页面单击-iOS?
我的情况是,我在C# 如何检测Xamarin表单选项卡式页面单击-iOS?,c#,xamarin.ios,xamarin.forms,C#,Xamarin.ios,Xamarin.forms,我的情况是,我在Xamarin表单中有一个选项卡页面: public partial class MainPage : TabbedPage { public MainPage() { InitializeComponent(); var playPage = new NavigationPage(new PlayPage()) { Title = "Play", Icon = "p
Xamarin表单中有一个选项卡
页面
:
public partial class MainPage : TabbedPage
{
public MainPage()
{
InitializeComponent();
var playPage = new NavigationPage(new PlayPage())
{
Title = "Play",
Icon = "play.png"
};
var settingsPage = new NavigationPage(new SettingsPage())
{
Title = "Settings",
Icon = "settings.png"
};
var favoritesPage = new NavigationPage(new FavoritesPage())
{
Title = "Favorites",
Icon = "fave.png"
};
var aboutPage = new NavigationPage(new AboutPage())
{
Title = "About",
Icon = "info.png"
};
Children.Add(playPage);
Children.Add(favoritesPage);
Children.Add(settingsPage);
Children.Add(aboutPage);
}
}
我想在我的应用程序中添加暂停和播放功能。启动时,PlayPage
最初会有play.png
图标,当我再次点击PlayPage
时,它会将图标更改为pause.png
。页面不只是更改页面图标。有人知道怎么做吗
编辑:
因此,我创建了一个自定义渲染器,在OnElementChanged
中,我使用了ViewControllerSelected
:
var tabbarController = (UITabBarController)this.ViewController;
if (null != tabbarController)
{
tabbarController.ViewControllerSelected += OnTabBarReselected;
}
我的OnTabBarReselected
我有:
private void OnTabBarReselected(object sender, UITabBarSelectionEventArgs e)
{
switch (TabBar.SelectedItem.Title)
{
case "Play":
TabBar.SelectedItem.Title = "Pause";
TabBar.SelectedItem.Image = UIImage.FromFile("pause.png");
break;
}
}
这只做了一半的工作。单击同一选项卡(而非
图标
)后,它会将所选选项卡栏的标题
从播放
更改为暂停
。图标保持为“play.png”,直到我离开该选项卡页面(选择另一个选项卡)。有人知道为什么吗 您需要实现一个自定义渲染器来实现这一点。詹姆斯·蒙特马诺(James Montemagno)的博客上有一些关于更改图标的实现
- iOS:
- 机器人:
TabbedPage
中覆盖一个OnCurrentPageChanged
事件,但当页面已处于活动状态时,不会调用该事件