This is a migrated thread and some comments may be shown as answers.

RootFrame.Template - NullReferenceException

6 Answers 81 Views
PhoneApplicationFrame
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Edouard
Top achievements
Rank 1
Edouard asked on 03 Jun 2011, 08:02 PM

Hi,

I'm playing webradios in my app (on each page), so I'm using a SmoothStreamingMediaElement in the App.xaml page.

Here is the Silverlight code for the template, in the <Application.resources> markup :

<ControlTemplate x:Key="MediaFrameTemplate" TargetType="phone:PhoneApplicationFrame">
            <Border x:Name="ClientArea" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" >
                <Grid x:Name="MediaElementContainer">
                    <smooth:SmoothStreamingMediaElement Name="SSME_media" Volume="1.0" AutoPlay="True" Loaded="SSME_media_Loaded" />
                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
                </Grid>
            </Border>
        </ControlTemplate>

Here is the C# code, in the InitializePhoneApplication method :

RootFrame.Template = App.Current.Resources["MediaFrameTemplate"] as ControlTemplate;

I'm using que Q2 2011 Beta, because I'm getting issues with the LoopingList when I'm launching several times the same page ( http://www.telerik.com/community/forums/windows-phone/loopinglist/loopinglistdatasource-may-not-be-associated-with-multiple-looping-lists.aspx ). I'm using a RadPhoneApplicationFrame instead of the PhoneApplicationFrame. With the Q1 2011 it's ok, with a simple PhoneApplicationFrame it's ok, but with the RadPhoneApplicationFrame of the Q2 2011 Beta tools, I'm getting that exception :
System.NullReferenceException was unhandled
  Message=NullReferenceException
  StackTrace:
    à Telerik.Windows.Controls.RadPhoneApplicationFrame.OnApplyTemplate()
    à System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)

Thanks for your help,

6 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 08 Jun 2011, 11:47 AM
Hi Edouard,

The reason for the exception is that the RadTransitionControl is removed from the ControlTemplate of the RadPhoneApplicationFrame.

We will fix the null ref. exception for the official release. Thanks for pointing this out!

But - if you remove the RadTransitionControl from the RadPhoneApplicationFrame the latter will not behave as it should - e.g. no transitions will be played. And in this case - you better use the one found in the Silverlight framework - e.g. the simple PhoneApplicationFrame.

I added 1000 Telerik points to your account. Thanks again for the feedback!

All the best,
Valentin.Stoychev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Edouard
Top achievements
Rank 1
answered on 08 Jun 2011, 11:54 AM
Hi Valentin,

Thanks for your answer.

So, until the final release is available, I can't use the RadTransitionControl ? (or the LoopingList)

Is the date of the final release already available ?

Best regards,

Edouard
0
Valentin.Stoychev
Telerik team
answered on 08 Jun 2011, 11:58 AM
Hello Edouard,

You can, but you need to slightly modify the control template of the RadApplicationFrame. You need to replace the contentPresenter with a RadTransitionControl in order the RadApplicationFrame to behave correctly.

 Here it is how to do it:
<ControlTemplate x:Key="MediaFrameTemplate" TargetType="phone:PhoneApplicationFrame"
            <Border x:Name="ClientArea" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"
                <Grid x:Name="MediaElementContainer"
                    <smooth:SmoothStreamingMediaElement Name="SSME_media" Volume="1.0" AutoPlay="True" Loaded="SSME_media_Loaded" /> 
                     <telerikPrimitives:RadTransitionControl 
                                x:Name="TransitionControl" 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
                                Margin="{TemplateBinding Padding}" 
                                Content="{TemplateBinding Content}" 
                                ContentTemplate="{TemplateBinding ContentTemplate}" 
                                Transition="{TemplateBinding Transition}">
  
                            </telerikPrimitives:RadTransitionControl
                </Grid
            </Border
        </ControlTemplate>


Please try this approach and let us know how it goes.

Kind regards,
Valentin.Stoychev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Edouard
Top achievements
Rank 1
answered on 08 Jun 2011, 12:15 PM
Thanks for your really fast answer !

With your template I was getting an "unspecified error".

But I replaced the TargetType (phone:PhoneApplicationFrame) in your code by telerikPrimitives:RadPhoneApplicationFrame, and now it's working great.

Thanks again !

Best regards,

Edouard
0
Edouard
Top achievements
Rank 1
answered on 16 Jun 2011, 06:51 PM
Hi,

I'm writing back to this thread because I want to add a background image to my app (the background must be visible during transitions).

i'm using this code to set the background image :
var ib = new ImageBrush();
ib.ImageSource = new BitmapImage(new Uri("SplashScreenImage.jpg", UriKind.Relative));
ib.Stretch = Stretch.None;
ib.AlignmentY = AlignmentY.Bottom;
RootFrame.Background = ib;
SplashScreenImage.jpg has its "Build Action" set to "Content".

It's working great without the Template. But when I set the template :
RootFrame.Template = App.Current.Resources["MediaFrameTemplate"] as ControlTemplate;
The background didn't change.

Thanks by advance.

Best regards,

Edouard
0
Valentin.Stoychev
Telerik team
answered on 21 Jun 2011, 07:56 AM
Hello Edouard,

Can you send us a project where we can investigate the issue. In the template everything looks OK, so there should be something else wrong.

Thanks!

Best wishes, Valentin.Stoychev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
PhoneApplicationFrame
Asked by
Edouard
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Edouard
Top achievements
Rank 1
Share this question
or