RootFrame.Template - NullReferenceException

7 posts, 0 answers
  1. Edouard
    Edouard avatar
    7 posts
    Member since:
    Mar 2011

    Posted 03 Jun 2011 Link to this post

    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,
  2. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 08 Jun 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Edouard
    Edouard avatar
    7 posts
    Member since:
    Mar 2011

    Posted 08 Jun 2011 Link to this post

    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
  5. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 08 Jun 2011 Link to this post

    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>>
  6. Edouard
    Edouard avatar
    7 posts
    Member since:
    Mar 2011

    Posted 08 Jun 2011 Link to this post

    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
  7. Edouard
    Edouard avatar
    7 posts
    Member since:
    Mar 2011

    Posted 16 Jun 2011 Link to this post

    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
  8. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 21 Jun 2011 Link to this post

    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>>
Back to Top
DevCraft banner