Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WPF - GridLength GridUnitType.Auto

Tags:

c#

wpf

gridlength

Can anyone explain the difference between using:

 GridLength length = new GridLength(0, GridUnitType.Auto) 

and

 GridLength length = new GridLength(1, GridUnitType.Auto)

My limited knowledge of this leads me to believing these would both be identical solutions due to auto being as it states..."auto", therefore making the double value redundant.

Most examples I have seen show the GridUnitType.Auto being preceded with 1 rather than 0, but it seems to me that either option works the same?

Is this the case or can anyone shed some light on if/how these are different

like image 902
shann1990 Avatar asked Jul 31 '13 15:07

shann1990


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

How old is the letter C?

The letter c was applied by French orthographists in the 12th century to represent the sound ts in English, and this sound developed into the simpler sibilant s.


1 Answers

I think your understanding is correct, when the value GridUnitType.Auto is used, the first value passed to the constructor is redundant, as the size will be determined by the content object.

It somewhat makes sense in the context of the GridLength structure constructor to retain this parameter (even though it's not used in this instance), as it allows the second parameter type to contain values that describe the all available states of GridUnitType.

From the documentation:

The enumerated type GridUnitType can contain the following values:

Auto   - The size is determined by the size properties of the content object. 
Pixel  - The value is expressed as a pixel. 
Star   - The value is expressed as a weighted proportion of available space. 

So really, the first parameter is only relevant when the second parameter is set to GridUnitType.Pixel or GridUnitType.Star.

It wouldn't work neatly other way around e.g. if you tried to have constructor that accepted 1 parameter as a GridUnitType, and only required the second parameter if you used Pixel or Star.

This way round, you get the benefit of having a 1 parameter constructor that accepts a double without specifying the additional type. Although it does have the cost of a potentially odd looking two parameter constructor when using Auto (as in your example).

like image 170
Chris Avatar answered Sep 20 '22 22:09

Chris