【发布时间】:2015-03-30 11:56:46
【问题描述】:
我是 windows phone 的新手,与 windows phone 8 相比,windows phone 8.1 似乎有很多变化。如何在全局范围内更改我的应用程序的背景图像,而不是在每个视图中一次又一次地声明它.
【问题讨论】:
标签: xaml background windows-phone-8.1
我是 windows phone 的新手,与 windows phone 8 相比,windows phone 8.1 似乎有很多变化。如何在全局范围内更改我的应用程序的背景图像,而不是在每个视图中一次又一次地声明它.
【问题讨论】:
标签: xaml background windows-phone-8.1
在 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 的背景 -> 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>
希望对你有帮助
【讨论】: