如何使用弹出按钮在xamarin shell标题中设置背景图像?
我正在开发一个Xamarin.Forms 4项目,我正在使用应用程序外壳 我使用的是Tabbar,多亏了定制的渲染器,我在“标题”中添加了背景图像 在如何使用弹出按钮在xamarin shell标题中设置背景图像?,shell,xamarin,xamarin.forms,flyout,Shell,Xamarin,Xamarin.forms,Flyout,我正在开发一个Xamarin.Forms 4项目,我正在使用应用程序外壳 我使用的是Tabbar,多亏了定制的渲染器,我在“标题”中添加了背景图像 在 //其他选项卡。。。 我也跟着去了 我得到了这个 现在我必须添加侧菜单,我用以下代码替换了前面的AppShell.xaml代码: <FlyoutItem FlyoutDisplayOptions="AsMultipleItems"> <ShellContent Title="ANALYSIS"
//其他选项卡。。。
我也跟着去了
我得到了这个
现在我必须添加侧菜单,我用以下代码替换了前面的AppShell.xaml代码:
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<ShellContent Title="ANALYSIS"
Icon="chart_icon.png"
ContentTemplate="{DataTemplate local:Reports.ReportsPage}" />
//other tabs...
</FlyoutItem>
//其他选项卡。。。
我明白了:
(图标是临时的,代表汉堡菜单图标根据您的描述,我认为您希望为工具栏而不是tabbar设置背景图像 自定义渲染器可以做到这一点 MyShell.cs
public class MyShell:Shell
{
}
AppShell.xaml.cs注意:AppShell需要继承MyShell
public partial class AppShell : MyShell
{
public AppShell()
{
InitializeComponent();
}
}
MyShellRenderer.cs
[assembly: ExportRenderer(typeof(MyShell), typeof(MyShellRenderer))]
namespace ShellDemo.Droid
{
public class MyShellRenderer : ShellRenderer
{
public MyShellRenderer(Context context) : base(context)
{
}
protected override IShellToolbarAppearanceTracker CreateToolbarAppearanceTracker()
{
return new CustomToolbarAppearanceTracker();
}
}
public class CustomToolbarAppearanceTracker : IShellToolbarAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(Android.Support.V7.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker)
{
}
public void SetAppearance(Android.Support.V7.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
{
toolbar.SetBackgroundResource(Resource.Drawable.pink);
}
}
}
我发现我写错了shell XAML,这就是解决方案
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<Tab Title="ANALYSIS"
Icon="chart_icon.png">
<ShellContent ContentTemplate="{DataTemplate local:Reports.ReportsPage}" />
</Tab>
<!-- others tabs -->
</FlyoutItem>
在“Xanimals”示例之后,我不理解“标签”标签的重要性,应用程序返回该标签使用所有样式和渲染器。嗨,这不起作用,这是我已经拥有的渲染器。(我链接的是Microsoft页面)我已经用IShellToolbarAppearanceTracker而不是ShellToolbarAppearanceTracker更新了它,就像你的例子一样,但它不起作用…它对我起作用。你的代码有错误吗?没有,我没有代码错误…在开始使用FlyoutItem而不是TabBar之前,它对我也起作用。你是使用TabBar还是FlyoutItem?或者两者都有?我只要使用一个Shell模板项目。如果这是您想要的,我可以在GitHub上发布示例代码。从您的GIF中,我看到您没有侧菜单…我在开始使用侧菜单时遇到了这个问题,如果我回滚到Shell中使用,我没有这个问题。我看到您来自Microsoft团队,您有使用侧菜单的示例吗?
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<Tab Title="ANALYSIS"
Icon="chart_icon.png">
<ShellContent ContentTemplate="{DataTemplate local:Reports.ReportsPage}" />
</Tab>
<!-- others tabs -->
</FlyoutItem>