在XAML中定义了一个控件,如下:
<Grid x:Name="FormContainerElement" ... />
自定义控件代码*.cs如下:
[TemplatePart(Name = "FormContainerElement", Type = typeof(Grid))]
public class MyControl : Control
{
public MyControl()
{
DefaultStyleType = typeof(MyControl);
}
private Grid formContainerElement;
private Grid FormContainerElement
{
get
{
return formContainerElement;
}
set
{
formContainerElement = value;
}
}
public override void OnApplyTemplate()
{
FormContainerElement = GetTemplateChild("FormContainerElement") as Grid;
base.OnApplyTemplate();
}
}
红色标注的方法将XAML中的控件负责和*.cs中的控件绑定,一定不能缺少,否则...
Silverlight的呈现和逻辑分离有点似曾相识,JSF好像...