Ladislav Mrnka
Ladislav Mrnka

Reputation: 364399

The name 'GridLengthHelper' does not exist in the current context

I'm reading Metro Revealed: Building Windows 8 Apps with XAML and C#. The book contains this snippet of code which I'm not able to compile:

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);
    }
}

The problem is with GridLengthHelper class which is not visible for Visual Studio (tried in both VS 2012 Express for Windows 8 RC and VS 2012 Ultimate RC). The build error is:

The name 'GridLengthHelper' does not exist in the current context

or

'Windows.UI.Xaml.GridLengthHelper' is inaccessible due to its protection level

The Object Browser doesn't show this class in Windows.winmd where it should be according to the documentation. What is even more frustrating when I navigate to the path displayed in the Object Browswer:

C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral\Windows.winmd

and open the Windows.winmd file in Reflector, I see that the public GridLengthHelper class is present!

Upvotes: 0

Views: 408

Answers (1)

Filip Skakun
Filip Skakun

Reputation: 31724

You can just use new GridLength(pixels) or new GridLength(starWidth, GridUnitType.Star)

Upvotes: 1

Related Questions