Another hour, another problem..
Anyone else having problems with binding to a ColumnDefinition Width?
This is my xaml:
<Grid BackgroundColor="#f00" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding HalfScreenWidth}" />
<ColumnDefinition Width="{Binding HalfScreenWidth}" />
</Grid.ColumnDefinitions>
<Image Source="xx.png" Grid.Row="0" Grid.Column="0" BackgroundColor="#0f0" />
<Image Source="xx.png" Grid.Row="0" Grid.Column="1" BackgroundColor="#00f" />
</Grid>
in my view model I define HalfScreenWidth like this:
public GridLength HalfScreenWidth { get; set; }
I have tried with different input, e.g.:
HalfScreenWidth = new GridLength (50);
But it's all ignored.
Another bug? Or me misunderstanding something?
I can bind to the property from a Label with no problem like this:
<ContentPage.Resources>
<ResourceDictionary>
<local:GridLengthToStringConverter x:Key="gridLengthConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<Label Text="{Binding HalfScreenWidth, Converter={StaticResource gridLengthConverter}" />
Having implemented a converter like this:
class GridLengthToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var gl = (GridLength)value;
return String.Format("Gridlength: {0}", gl.Value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return new GridLength (10); // not used..
}
}
The label shows the expected string (e.g. "Gridlength: 50")
Thanks in advance,