Hi experts,
As subject, here is my XAML code. But I got "There is no Height and Width property...." exception while compiling. I know the type of Height and Width should be GridLength but I have no idea to specify in ResourceDictionary.
<ContentPage.Resources> <ResourceDictionary> <OnPlatform x:Key="GridSize" x:TypeArguments="x:Double" iOS="50" Android="100" WinPhone="100" /> </ResourceDictionary> </ContentPage.Resources> ........ <Grid> <Grid.RowDefinitions> <RowDefinition Height="{StaticResource GridSize}" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <RowDefinition Height="{StaticResource GridSize}" /> </Grid.ColumnDefinitions> </Grid>
Any directions and hints will be appreciated. Thanks in advance.
Answers
Look at this
http://forums.xamarin.com/discussion/18841/custom-cell-in-table-using-grid-via-xaml
That does not help. The Row and Column definition in Grid View does not accept integer or double.
Well, probably this is not your problem, but just in case... Is it true that inside your ColumnDefinitions tag you have RowDefinition?
It is typo. it should be
After performed some research and found the value of Height and Width should be converted to GridLength and it is needed to create a new class which implement IValueConverter. I'll try to see if it could solve my problem.
I'm stumped on this one as well, has anyone figured it out yet?
Yes Terry Lin, you need to use GridLength.
this work for me,
30
I ended up doing the following, so I am binding the
RowDefinition
'sHeight
property to aGridLength
property in my ViewModel. And then in my ViewModel's constructor, I specify a different height based on the Device OS:XAML:
<Grid.RowDefinitions> <RowDefinition Height="{Binding RowHeight}" /> </Grid.RowDefinitions>
ViewModel:
Could not (and did not have enough time to) successfully make it work in the XAML code.
OnPlatform Grid Height & Width Definition in XAML Code:
@DerekvanNiekerk
Thanks!
Thanks @DerekvanNiekerk!
The
20*
Xaml syntax forGridLength(20, GridUnitType.Star)
was exactly I have been looking for.Why couldn't I find it anywhere in the documentation?
the new way
This even works in staticResources. Including the star notation.