我是Windows手机的新手,看起来Windows手机8.1与Windows手机相比有很多变化。如何在全球范围内更改我的应用的背景图片,而不是在每个视图中一次又一次地声明它。
答案 0 :(得分:0)
在App.xaml中声明ImageBrush
<Application x:Class="App1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1">
<Application.Resources>
<ImageBrush x:Key="BgImage" ImageSource="Assets/Logo.png" />
</Application.Resources>
</Application>
在App.xaml.cs中设置rootFrame的背景 - &gt; OnLaunched方法:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
// TODO: diesen Wert auf eine Cachegröße ändern, die für Ihre Anwendung geeignet ist
rootFrame.CacheSize = 1;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Zustand von zuvor angehaltener Anwendung laden
}
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
if (rootFrame.ContentTransitions != null)
{
this.transitions = new TransitionCollection();
foreach (var c in rootFrame.ContentTransitions)
{
this.transitions.Add(c);
}
}
rootFrame.ContentTransitions = null;
rootFrame.Navigated += this.RootFrame_FirstNavigated;
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
rootFrame.Background = (ImageBrush)Resources["BgImage"];
Window.Current.Activate();
}
而不是让你的页面背景透明。
这是我的Page.xaml:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<TextBlock Text="Hello World !"/>
</Grid>
</Page>
希望有所帮助