我试图以某种方式自定义PhoneApplicationFrame,但我不明白我该怎么做才能继续。
让我解释一下:我正在研究WP 8应用程序,我希望它具有背景声音和声音效果(同时)。在this post询问帮助后,我被告知使用MediaElement
并将其添加到XAML
的{{1}}中(这是正确的吗?)。
我在这件事上做了什么:
我创建了一个框架(称为IntroFrame)并将其设置为PhoneApplicationFrame
文件中的RootFrame
。所以它是:
App.xaml.cs
在public partial class App
{
public static IntroFrame RootFrame {get; private set;}
...
}
方法中,我修改了代码:
InitializePhoneApplication
在XAML中,我尝试添加private void InitializePhoneApplication()
{
...
RootFrame = new IntroFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
...
}
:
MediaElement
框架似乎很好,我尝试了像here一样的高度技巧并且它有效。但是,我尝试自定义该Frame,添加可视元素,以更改MediaElement,没有任何效果。我猜<phone:PhoneApplicationFrame
x:Class="PazaakPhone.IntroFrame"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<MediaElement x:Name="BackgroundMedia" Source="Assets/Audio/bgm.mp3" AutoPlay="True" />
</phone:PhoneApplicationFrame>
的内容不能像PhoneApplicationFrame
那样?我认为我可以在后台执行此操作,而Frame,托管所有其他页面。但无论是我走错了路还是我错过了什么。它可能是什么?
答案 0 :(得分:4)
您可以通过重新模板PhoneApplicationFrame实现此目的:
<Application.Resources>
<Style x:Key="myPhoneApplicationFrameStyle" TargetType="phone:PhoneApplicationFrame">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="phone:PhoneApplicationFrame">
<Grid x:Name="MediaElementContainer" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<MediaElement Grid.Row="0" x:Name="MediaElement" Source="Assets/Audio/bgm.mp3" AutoPlay="True" Volume="1.0" Visibility="Collapsed" />
<Grid Grid.Row="1" x:Name="ClientArea">
<ContentPresenter />
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
然后在app.cs中设置样式:
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
RootFrame = new PhoneApplicationFrame { Style = Resources["myPhoneApplicationFrameStyle"] as Style };
RootFrame.Navigated += CompleteInitializePhoneApplication;
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}