XAML解析异常:属性{staticresource sphoncentbrush}值超出范围
-
14-11-2019 - |
题
我有一个例外问题,找不到如何解决它的答案。 属性{staticresource spheacentbrush}值超出范围。
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")));
.
在Windows Phone时,当我点击App_Info_Button时,System.Windows.apllication.loadComponent发生在App_info.g.i.cs中的例外时,上面的代码来自该文件。
以下是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>
.
这是堆栈跟踪
在system.windows.Application.LoadComponent(对象组件,URI Resourcelocator) 在pak_phone_side.app_info.initializeComponent() 在pak_phone_side.app_info..ctor() 在system.reflection.runtimeconstructorInfo.internalInvoke(RuntimeConstructorInfo RTCI,BindingFlags Invokeattr,BindingFlags Invokeattr,BindingBinder,对象参数,CultureInfo文化,布尔斯基金德,汇编来电者,Boolean ReveryAccess,StackCrawlmark&Stackmark) 在system.reflection.runtimeConstructorInfo.internalInvoke(Object Obj,BindingFlags Invokeattr,Binder Binder,Object []参数,CultureInfo Culture,StackCrawlmark&Stackmark) 在System.Activator.InternalCreateInstance(类型类型,布尔非公开,StackCrawlmark&Stackmark) 在system.activator.createinstance(类型类型) 在system.windows.navigation.pageresourcecontloader.beginload_onuithread(asynccallback usercallback,pageresourceCecontLoaderAsyncresult结果) 在System.Windows.Navigation.PageresourceCecontopler。<> C_ DisplayClass4.B _0(对象args) 在system.reflection.runtimemethodinfo.internalinvoke(Runtimemethodinfo RTMI,Object OBJ,BindingFlags Invokeattr,Binder Binder,对象参数,CultureInfo Culture,Boolean IsbinderDefault,汇编来电,Boolean FirederAccess,StackCrawlmark&Stackmark) 在system.reflection.runtimemethodinfo.internalinvoke(Object Obj,BindingFlags Invokeattr,Binder Binder,Object []参数,CultureInfo Culture,StackCrawlmark&Stackmark) 在system.reflection.methodbase.invoke(对象obj,对象[]参数) 在system.delegate.dynamicInvokeone(对象[] args) 在system.multicastdelegate.dynamicinvokeimpl(对象[] args) 在system.delegate.dynamicInvoke(对象[] args) 在system.windows.threading.dispatcheroperation.invoke() 在system.windows.threading.dispatcher.dispatch(DispatcherPriority Priority) 在system.windows.threading.dispatcher.oninvoke(对象上下文) 在System.Windows.Hosting.CallBackCookie.Invoke(对象[] args) 在system.windows.hosting.delegatewrapper.internalInvoke(对象[] args) 在System.Windows.Runtimehost.ManagedHost.Invokedelegate(Intptr Phandle,Int32 Nparamcount,ScriptParam [] PParams,ScriptParam&Presult)
解决方案
问题在于这一行:
<TextBlock Height="311" HorizontalAlignment="Center"
Margin="25,32,0,0" Name="textBlock1"
Text="This Application is designed ...."
VerticalAlignment="Center" Width="425"
Style="{StaticResource PhoneAccentBrush}" />
.
您正在尝试将刷子资源值设置为样式,这是导致异常的原因。您可以尝试将XAML更改为:
<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}" />
.