0

I have a problem with an Exception, couldn't find the answer on how to fix it. Attribute {StaticResource PhoneAccentBrush} value is out of range.

System.Windows.Application.LoadComponent(this, new System.Uri("/PAK_phone_side;component/Views/About/App_info.xaml", System.UriKind.Relative));
        this.LayoutRoot = ((System.Windows.Controls.Grid)(this.FindName("LayoutRoot")));
        this.TitlePanel = ((System.Windows.Controls.StackPanel)(this.FindName("TitlePanel")));
        this.ApplicationTitle = ((System.Windows.Controls.TextBlock)(this.FindName("ApplicationTitle")));
        this.PageTitle = ((System.Windows.Controls.TextBlock)(this.FindName("PageTitle")));
        this.ContentPanel = ((System.Windows.Controls.Grid)(this.FindName("ContentPanel")));
        this.textBlock1 = ((System.Windows.Controls.TextBlock)(this.FindName("textBlock1")));

In windows phone when i click on the button App_info_Button the exception happens on System.Windows.Apllication.LoadComponent In App_info.g.i.cs , the code above is from that file.

here is the content Panel definition on App_info.xaml

 <phone:PhoneApplicationPage 
x:Class="windowsphoneapp.App_info"
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}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="PAK " Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="App Infos" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <TextBlock Height="311" HorizontalAlignment="Center" Margin="25,32,0,0" Name="textBlock1" Text="This Application is designed ...." 
                   VerticalAlignment="Center" Width="425" Style="{StaticResource PhoneAccentBrush}" />
    </Grid>
</Grid>    
</phone:PhoneApplicationPage>

This is the Stack trace

at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at PAK_phone_side.App_info.InitializeComponent() at PAK_phone_side.App_info..ctor() at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type) at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result) at System.Windows.Navigation.PageResourceContentLoader.<>c_DisplayClass4.b_0(Object args) at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Delegate.DynamicInvokeOne(Object[] args) at System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at System.Delegate.DynamicInvoke(Object[] args) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority) at System.Windows.Threading.Dispatcher.OnInvoke(Object context) at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args) at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args) at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

Praetorian
  • 106,671
  • 19
  • 240
  • 328
404Dreamer_ML
  • 890
  • 3
  • 14
  • 25
  • 'PhoneAccentBrush` is a valid system resource so should be resolvable from anywhere. Can you post the XAML code that includes the supposedly invalid attribute, please? (presumably it's higher up the visual tree than what you've shown so far) – Derek Lakin Feb 15 '11 at 16:22
  • The XAML doesn't contain a lot of this it a simple one – 404Dreamer_ML Feb 15 '11 at 17:00
  • @Derek i edit in the question text – 404Dreamer_ML Feb 15 '11 at 17:03
  • Where in the code are you referencing PhoneAccentBrush? What's the XAML representation of App_info.xaml? – Den Feb 15 '11 at 17:23
  • @404Dreamer_ML: There is still no instance of `StaticResource PhoneAccentBrush` in the XAMl you've posted. I've gotten the "value is out of range" exception when I've tried to assign the wrong static resource type, for instance, trying to assign a brush to a style. – Praetorian Feb 15 '11 at 17:26
  • Thanks for updating your XAML. As mentioned above, you haven't used the **PhoneAccentBrush** in this XAML, so presumably this isn't the XAML that's causing the problem. – Derek Lakin Feb 16 '11 at 08:15
  • @All I am not using any PhoneAccentBrush in the code i wrote, that seems very weird, even i don't know really what is the purpose of the .g.i.cs file – 404Dreamer_ML Feb 16 '11 at 09:55
  • This may help: the Stack trace* – 404Dreamer_ML Feb 16 '11 at 10:25
  • 1
    The exception being raised explicitly mentions the PhoneAccentBrush resource, so that's the source of the problem. According to the exception details, the problem page is App_info.xaml, but you are showing us the XAML for MainPage.xaml. – Derek Lakin Feb 16 '11 at 10:30

1 Answers1

2

The problem is in this line:

<TextBlock Height="311" HorizontalAlignment="Center" 
           Margin="25,32,0,0" Name="textBlock1" 
           Text="This Application is designed ...." 
           VerticalAlignment="Center" Width="425" 
           Style="{StaticResource PhoneAccentBrush}" />

You are trying to set a brush resource value to a style, which is what is causing the exception. You could try changing the XAML to:

<TextBlock Height="311" HorizontalAlignment="Center" 
           Margin="25,32,0,0" Name="textBlock1" 
           Text="This Application is designed ...." 
           VerticalAlignment="Center" Width="425" 
           Style="{StaticResource PhoneTextNormalStyle}"
           Foreground="{StaticResource PhoneAccentBrush}" />
Praetorian
  • 106,671
  • 19
  • 240
  • 328