在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好像...

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2021-06-24
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2021-12-21
  • 2021-08-31
  • 2021-09-28
相关资源
相似解决方案