为什么visual studio会给我这种预期的错误类型

时间:2015-03-21 08:34:14

标签: c# windows-phone-8.1

当我想启动模拟器时,我正在开发Windows Phone 8.1应用程序给我这个错误" Type expected"第27行这是代码行:

statusBar.BackgroundColor = new ((SolidColorBrush)Windows.UI.Xaml.Application.Current.Resources["PhoneAccentBrush"]);

`

2 个答案:

答案 0 :(得分:2)

错误很明显,您没有告诉类型名称:

statusBar.BackgroundColor = new (...);
                         -------^

现在,你有一个SolidColorBrush(投射后),但你正试图获得Color。幸运的是,SolidColorBrush有一个Color属性,这是我怀疑你想要的:

var brush = (SolidColorBrush) Application.Current.Resources["PhoneAccentBrush"];
statusBar.BackgroundColor = brush.Color;

答案 1 :(得分:0)

您正在尝试使用new运算符,该运算符需要类型,如下所示:

variable = new SomeType(constructorArguments);

你有new然后是演员。

怀疑你只想要演员,没有new

// With a using directive for Windows.UI.Xaml...
statusBar.BackgroundColor = (SolidColorBrush) Application.Current.Resources["PhoneAccentBrush"];
相关问题