VasileF
VasileF

Reputation: 2916

PhoneApplicationFrame customization has no effect

I am trying to customize a PhoneApplicationFrame in some way but I don't understand how do I have to proceed.

Let me explain a little : I'm working on a WP 8 application which I want to have a background sound and sound effects (simultaneosly). After asking help, on this post, I have been advised of using a MediaElement and add it in the XAML of the PhoneApplicationFrame (is this correct?).

What have I done in this matter :

I created a frame (called IntroFrame) and set it as the RootFrame in App.xaml.cs file. So it is :

public partial class App
{
    public static IntroFrame RootFrame {get; private set;}
    ...
}

And in the InitializePhoneApplication method, I adapted the code :

private void InitializePhoneApplication()
{
   ...
   RootFrame = new IntroFrame();
   RootFrame.Navigated += CompleteInitializePhoneApplication;
   ...
}

In the XAML, I tried to add the 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>

The Frame seems fine, I tried the height trick like here and it worked. However, I tried to customize that Frame, to add visual elements, to change that MediaElement and nothing... no effect. I guess PhoneApplicationFrame can't have content like a PhoneApplicationPage? I thought I could do this in the background while the Frame, hosts all the other pages. But either I am on the wrong path or I am missing something. What could it be?

Upvotes: 1

Views: 840

Answers (1)

Ismael
Ismael

Reputation: 361

You can achieve this by re-templating the 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>

and then setting the style in the 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;
}

Upvotes: 4

Related Questions