简体   繁体   English

有什么办法可以在导航栏上逐页在xamarin表单上添加背景图像

[英]Is there any way to add background Image on navigationbar page by page on xamarin forms

Is there any way to add background Image on navigationbar page by page on xamarin forms? 有什么方法可以在xamarin表单上逐页在导航栏上添加背景图像吗?

这必须更改每一页

The would need to write a custom render to change the background of the navigation bar. 需要编写自定义渲染来更改导航栏的背景。 This is simply because the navigation bar does not have an option to change the background image. 这仅仅是因为导航栏没有用于更改背景图像的选项。

https://books.google.co.uk/books/about/Xamarin_Forms_Solutions.html?id=wvt9DwAAQBAJ&printsec=frontcover&source=kp_read_button&redir_esc=y#v=onepage&q&f=false https://books.google.co.uk/books/about/Xamarin_Forms_Solutions.html?id=wvt9DwAAQBAJ&printsec=frontcover&source=kp_read_button&redir_esc=y#v=onepage&q&f=false

There's a good very brief section about how to write custom renders is this ^ book (you can even find it in the preview without purchasing it). 这本^书有一个非常简短的小节,介绍如何编写自定义渲染(您甚至可以在预览版中找到它,而无需购买它)。

An alternative solution would be to create a custom banner at the top of the page 一种替代解决方案是在页面顶部创建自定义横幅

https://forums.xamarin.com/discussion/126227/customizing-navigation-bar-or-action-bar-in-xamarin-forms[As mentioned in this answer 2 https://forums.xamarin.com/discussion/126227/customizing-navigation-bar-or-action-bar-in-xamarin-forms [如该答案所述2

<ContentPage NavigationPage.HasNavigationBar="false">
    <StackLayout VerticalOptions="Start" 
                               HorizontalOptions="FillAndExpand" 
                               Orientation="Horizontal"          
                               Padding="10,5,10,5>
        <Image HorizontalOptions="StartAndExpand" source="yourimage.png"/>
        <Label HorizontalOptions="CenterAndExpand" Text="ALL"/>
        <Image HorizontalOptions="EndAndExpand" source="yourimage.png"/>
    </StackLayout>
    <StackLayout>
        <!-- Place your code for page body-->
    </StackLayout>
</ContentPage>

I've copied the code into here for simplicity and reference. 为了简单起见,我将代码复制到此处。 This solution removes the navigation bar and allows you to create a custom banner on each page in XAML. 此解决方案删除了​​导航栏,并允许您在XAML的每个页面上创建自定义横幅。 In here you can change the layout as you please. 在这里,您可以根据需要更改布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM