问题:动态创建控件,绑定了一个Style, 但是无法得到Style中Controltemplate的控件。

解决:

    GroupBox gb = new GroupBox();
            gb.Name = "groupbox1";
            gb.Header = "MyTest1";
            gb.Height = 50;
            gb.Width = 100;

 

           // 使用FindResource, 然后Apply

    gb.Style = this.FindResource("MyGroupBoxWithIcon") as Style;
            gb.ApplyTemplate();

    // 可以直接得到Image im2

    Image im2 = (Image)gb.Template.FindName("theImage", gb);

 

 

 

相关文章:

  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案