4
我想從後面的代碼訪問自定義控件的默認模板中的命名網格。
但是,即使在調用ApplyTemplate()之後,控件的模板似乎仍然爲null。
控件構造器內部不可能?
下面的代碼:從後面的代碼訪問自定義控件的WPF模板
Generic.xaml:
...
<ControlTemplate TargetType="{x:Type local:TimeTableControl}">
<Grid Name="ContentGrid">
</Grid>
</ControlTemplate>
...
TimeTableControl.cs:
public TimeTableControl()
{
ApplyTemplate();
contentGrid = (Grid)(Template.FindName("ContentGrid", this));
//Line above causes null-pointer-exception
...
}
謝謝,剛纔我做了什麼。我知道我採取了錯誤的做法...... :-) – 2010-04-28 14:58:55