我正在创建一个自定义控件并创建了一个bindable property
. 我想根据这些属性设置孩子。处理这种情况的正确方法是什么?我尝试在我可以连接的基本控件或事件中寻找任何有意义的东西。
例如,我想在Grid
设置ColumnCount
andRowCount
时创建 a 的列/行定义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); }
}
}