void UpdateGrid()
{
if (_grid == null)
{
return;
}
_grid.ColumnDefinitions.Clear();
_grid.RowDefinitions.Clear();
if (_converter == null)
{
_converter = new LayoutOptionsToLengthConverter();
}
if (_orientation == Orientation.Vertical)
{
for (int i = 0; i < ItemsControl.Items.Count; i++)
{
var element = _grid.Children.OfType <UIElement>().Skip(i).First();
WPFGrid.SetRow(element, i);
WPFGrid.SetColumn(element, 0);
var row = new WPFRowDefinition {
Height = new WPFGridLength(0, WPFGridUnitType.Auto)
};
_grid.RowDefinitions.Add(row);
var binding = new System.Windows.Data.Binding(View.VerticalOptionsProperty.PropertyName)
{
Source = ItemsSource.Skip(i).FirstOrDefault(),
Converter = _converter
};
row.SetBinding(WPFRowDefinition.HeightProperty, binding);
}
}
else
{
for (int i = 0; i < ItemsControl.Items.Count; i++)
{
var element = _grid.Children.OfType <UIElement>().Skip(i).First();
WPFGrid.SetRow(element, 0);
WPFGrid.SetColumn(element, i);
var col = new WPFColumnDefinition {
Width = new WPFGridLength(0, WPFGridUnitType.Auto)
};
_grid.ColumnDefinitions.Add(col);
var binding = new System.Windows.Data.Binding(View.HorizontalOptionsProperty.PropertyName)
{
Source = ItemsSource.Skip(i).FirstOrDefault(),
Converter = _converter
};
col.SetBinding(WPFColumnDefinition.WidthProperty, binding);
}
}
}