Xamarin形成所有页面的背景图像 [英] Xamarin forms background image for all Pages
问题描述
是否可以将图像设置为应用程序中所有页面的背景(对于所有平台IOS,Android和WP)?
It´s possible to set an image to be the background of all Pages on my application (for all platforms IOS, Android and WP) ?
页面具有BackgroundImage属性,因此我可以创建基本页面,设置背景并使我的所有页面都从该页面扩展.
Page has a BackgroundImage property, so I can create a base page, set the background and make all my pages extends from it.
我想知道是否有更合适的解决方案来解决这个问题.
I want to know if there is a more appropriate solution, to handle this.
推荐答案
You could use Styles in your App.cs :
public App ()
{
Application.Current.Resources.Add(new Xamarin.Forms.Style(typeof(Page)){
Setters = {
new Xamarin.Forms.Setter { Property = Page.BackgroundImageProperty, Value = "back.png"},
}
});
}
不太受欢迎或不建议使用,但为了显示其他选项,您可以将事件处理程序附加到NavigationPage
并从那里设置背景:
much less preferred or advised but for the sake of showing another option you could attach an event handler to your NavigationPage
s and set the background from there:
yourRootNavigationPage.Pushed+= (sender, e) => e.Page.BackgroundImage = "back.png";
这篇关于Xamarin形成所有页面的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!