After reading a related thread that was unanswered I decided to post my question to the forums in hopes that both threads may gain some traction. The related thread is: http://forums.xamarin.com/discussion/28654/grids-row-height-wrong-after-button-resize
I am having a problem with Image Width/Grid Cell Width. My application has images, uploaded by an administrator, that may be any size, but are typically larger than the space allocated for them. I have successfully managed to get my images to shrink and maintain the appropriate aspect ratio, however the width allocated to the grid cell containing the image does not appropriately scale down.
The issue seems to be linked to having set the width of the column definition associated with the grid cell containing my image to auto. I am unable to prove it, but if I had to guess... it seems that my column width is being set based on the original size of the image and is then not adjusted after the image is scaled down to fit within the height restriction of the grid cell. I should also mention that there is only one row in my grid and it's height is set to Star (*). The entire grid is located inside a different container with set a fixed size that constricts the width and height of this grid based on some settings by a content administrator.
Each of the grids I am trying to build will eventually function as a 'tile' and contain three columns (Image, Content Separator, Label). In each tile the image column is given priority and as such is set to Auto. The content separator will also be set to auto, but it is typically only a thin line 1-20 pixels wide. The label then should receive the lowest priority for space and as such is set to Star (*). Again this set-up seems to function appropriately however the image column is being allocated more space than necessary once the image is scaled down to the appropriate size.
A sample of my code is shown below:
contentLayout = new Grid()
{
VerticalOptions = labels.VerticalOptions,
HorizontalOptions = labels.HorizontalOptions,
ColumnDefinitions =
{
new ColumnDefinition { Width = GridLength.Auto },
new ColumnDefinition { Width = GridLength.Auto },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
},
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
}
};
if (contentImage != null)
{
contentLayout.Children.Add(contentImage, 0, 0);
}
if (separator != null)
{
contentLayout.Children.Add(separator, 1, 0);
}
if (labels != null)
{
contentLayout.Children.Add(labels, 1, 0);
}
I am relatively new to Xamarin Forms, and appreciate any all help anyone can offer me. Thank You!
Johnny