WPF继承窗口 或控件

WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义。继承自定义窗口的类xaml文件的根节点就不再是
而是自定义窗口类名(若自定义窗口与继承者不在同一个命名空间,还得加上命名空间),继承自定义窗口类后台代码也得修改为继承自自定义窗口
exp:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 //继承Window类的自定义窗口类 namespace  WPF_Study.Entity {     using  System.Windows;     public  class  WindowBase:Window      {          private  const  int  Fixed_Width = 540;          private  const  int  Fixed_Height = 350;          public  WindowBase() :  base ()          {              this .MaxWidth = Fixed_Width;              this .MaxHeight = Fixed_Height;              this .MinWidth = Fixed_Width;              this .MinHeight = Fixed_Height;          }      } } //继承自定义窗口 //xaml文件 "WPF_Study.TestWindowBase"          xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:localEntity= "clr-namespace:WPF_Study.Entity"          Title= "TestWindowBase"  >                                                           "40*" />              "221*" />                   "0"  Grid.Column= "0" >                                                                       "dataGrid"  AutoGenerateColumns= "False"  Grid.Row= "2"  Grid.Column= "0"  CanUserAddRows= "False" >                               "窗口编号"  Binding= "{Binding Win}" />                  "评价器地址"  Binding= "{Binding Evalutor}" />                  "条屏地址"  Binding= "{Binding StripeScreen}" />                  "IP"  Binding= "{Binding IP}" />                  "注册设备号"  Binding= "{Binding RegNum}" />                  "描述"  Binding= "{Binding Description}"  Width= "*" />                            //对应后台代码 using  WPF_Study.Entity; namespace  WPF_Study {      ///      /// Interaction logic for TestWindowBase.xaml      ///      public  partial  class  TestWindowBase : WindowBase      {          public  TestWindowBase()          {              InitializeComponent();          }      } }

  


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部