我正在阅读Metro Revealed:Building Windows 8 Apps with XAML and C#。这本书包含了我无法编译的代码片段:
using Windows.UI.Xaml;
...
private void HandleViewStateChange(ApplicationViewState viewState) {
if (viewState == ApplicationViewState.Snapped) {
GridLayout.ColumnDefinitions[0].Width
= GridLengthHelper.FromPixels(0);
} else {
GridLayout.ColumnDefinitions[0].Width
= GridLengthHelper.FromValueAndType(1, GridUnitType.Star);
}
}
问题在于GridLengthHelper
类,这对于Visual Studio是不可见的(在VS 2012 Express for Windows 8 RC和VS 2012 Ultimate RC中都尝试过)。构建错误是:
当前上下文中不存在名称“GridLengthHelper”
或
'Windows.UI.Xaml.GridLengthHelper'由于其保护级别而无法访问
对象浏览器不会在Windows.winmd
中显示此类,它应该是according to the documentation。当我导航到Object Browswer中显示的路径时,更令人沮丧的是:
C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\Windows.winmd
并在Reflector中打开Windows.winmd
文件,我看到公共GridLengthHelper
类已存在!
答案 0 :(得分:1)
你可以使用新的GridLength(像素)或新的GridLength(starWidth,GridUnitType.Star)