0
我是wpf的新手。我在寫日曆控件。我在Generic.xaml中定義了一個默認模板。所有的日期都被填充到列表框中。由於列表框是在模板中定義的,因此我使用FindName()來訪問該控件。問題是,我不認爲這是填充列表框的構造,因爲它的訪問模板控制(我相信在那個時候沒有初始化的方法。下面是填充如何使用默認值填充模板中使用的控件?
private void DisplayCurrentMonthContents()
{
int daysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, CurrentMonth);
TextBlock CurrentMonthTextBlock = GetTextBlock();
ListBox DateListBox = (ListBox)Template.FindName("PART_ListBox", this);
CurrentMonthTextBlock.Text = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(CurrentMonth);
DateListBox.Items.Clear();
for (int counter = 1; counter != daysInMonth; counter++)
{
DateListBox.Items.Add(counter);
}
}
代碼
我相信,我的「M接近它錯了。我怎麼能填充正在模板中使用默認值控制?