I'm creating a custom control and created a bindable property
. I wanted to setup the children based on these properties. What is the correct way of handling this scenario? I tried looking for anything that makes sense to override in a base control or events that I can hook up.
For example, I want to create the column/row definitions of a Grid
when I set the ColumnCount
and RowCount
in XAML
public class HeatMap: Grid
{
public HeatMap()
{
// Where should I move these?
Enumerable.Range(1, RowCount)
.ToList()
.ForEach(x => RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }));
Enumerable.Range(1, ColumnCount)
.ToList()
.ForEach(x => ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }));
}
public static readonly BindableProperty RowCountProperty =
BindableProperty.Create<HeatMap, int>(p => p.RowCount, 0);
public int RowCount
{
get { return (int)GetValue(RowCountProperty); }
set { SetValue(RowCountProperty, value); }
}
public static readonly BindableProperty ColumnCountProperty =
BindableProperty.Create<HeatMap, int>(p => p.ColumnCount, 0);
public int ColumnCount
{
get { return (int)GetValue(ColumnCountProperty); }
set { SetValue(ColumnCountProperty, value); }
}
}
Do you mean update columns/rows on when properties are updated?
BindableProperty.Create
has argumentpropertyChanged
to handle value updates.