xamarin - 如何在 Xamarin 表单中将背景图像设置为导航页面栏

标签 xamarin xamarin.forms

我正在寻找将 BackgroundImage 设置为 NavigationPage Xamarin.Forms 应用程序中的 NavBar,但我找不到答案。有人知道怎么做吗?我可以更改颜色属性,但我需要顶部栏中的公司 Logo 。

最佳答案

由于 Xamarin.Forms 框架不支持它,因此您需要为 NavigationBar 创建一个自定义渲染器(据我所知,要渲染的类是 NavigationRenderer导航页面渲染器)。

然后在 android 的渲染类中添加一个可绘制图像,在 iOS 中将 UIImage 添加到顶部栏。

编辑 - 我想到了另一种解决方案 - 不使用自定义渲染,您可以通过删除现有栏来实现此目的,方法是在每个页面中设置以下命令:

NavigationPage.SetHasNavigationBar(this, false)

并创建一个包裹在网格中的自定义导航栏,它应该看起来像这样:

<Grid>
   <Image Source="BackgroundImage.png"/> <!-- This should fill the grid -->
   <Image Source="back_button" HorizontalOptions="StartAndExpand" Aspect="AspectFit" >
      <Image.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding NavigateBackCommand}"/>
      </Image.GestureRecognizers>
    </Image>
</Grid>

关于xamarin - 如何在 Xamarin 表单中将背景图像设置为导航页面栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30806780/

相关文章:

c# - uiimageview ios Xamarin C#上的click事件

ios - 使用 ViewCellRenderer 在 iOS 上的 Xamarin Forms 中自动设置 ViewCell 高度

xamarin - 使用模板的新 Xamarin.Forms 解决方案失败

c# - Xamarin.Forms 中的多个阶梯 slider

c# - PropertyChanged 事件后的 ViewModels 属性始终为 Null

c# - 使用 xaml 自定义 View 中的嵌套元素

c# - 带有菜单/选项卡的 Xamarin Forms 轮播

xamarin - 如何在Xamarin表单中使用单选按钮

c# - MessagingCenter.Send 上的 System.Reflection.TargetInvocationException

xamarin - 我们可以使用 Xamarin.Forms for UWP 进行流畅的设计吗?