Так что мне нужно создать пользовательскую кнопку, на которой я должен создать сетку, и на этой сетке мне нужно создать несколько меток с определенной информацией.Это код, в который я добавляю дочерний элемент для кнопки
private void HighlightTodayDay()
{
Label label1 = new Label()
{
BackgroundColor = Color.DarkRed,
Text = "lbl1"
};
Label label2 = new Label()
{
BackgroundColor = Color.Gold,
Text = "lbl2"
};
if ((DateTime.Today.Year == actualVisibleMonth.Year) && (DateTime.Today.Month == actualVisibleMonth.Month))
{
foreach (var child in Children.Reverse())
{
if (child.ClassId.ToString() == ("actualDayButtonID" + DateTime.Today.Day.ToString()) && child.IsEnabled == true)
{
DayButton todayDayButton = dayButtonsList[DateTime.Today.Day + shiftOfFirstDay];
todayDayButton.TextColor = Color.FromHex("#0f0");
//upto this line everything is working as it should
todayDayButton.insideGrid.Children.Add(label1, 0, 0); //do nothing
todayDayButton.insideGrid.Children.Add(label2, 0, 1); //do nothing
return;
}
}
}
}
, а вот код для "пользовательской" кнопки
class DayButton : Button
{
public string EventDate;
public string EventStartTime;
public string EventEndTime;
public string EventShift;
public string EventName;
public string EventDescription;
public Grid insideGrid;
public DayButton()
{
insideGrid = new Grid();
insideGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
insideGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(3, GridUnitType.Star) });
insideGrid.Parent = this;
}
}
Это должно выглядеть следующим образом нажмите, чтобы увидеть изображение