WPF 继承自己设计的窗体控件

baseWin不能有XAML文件,只能是一个类
  1. namespace WPFStudy
  2. {
  3. public class MyBaseWin : Window
  4. {
  5. public MyBaseWin(int w, int h, String title) {
  6. this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  7. this.Width = w;
  8. this.Height = h;
  9. this.Title = title;
  10. this.FontSize = 50;
  11. }
  12. }
  13. }



子类继承注意需要改变的有两个地方,一个是cs文件的两个,一个是XAML文件
  1. public partial class WinTest : MyBaseWin
  2. {
  3. public WinTest(int w,int h,String title):base(w,h,title)
  4. {
  5. InitializeComponent();
  6. }
  7. }
  1. public partial class WinTest : WPFStudy.MyBaseWin, System.Windows.Markup.IComponentConnector {
  1. <my:MyBaseWin x:Class="WPFStudy.WinTest"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:my="clr-namespace:WPFStudy"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. >
  8. <Grid>
  9. <Label Content="test"></Label>
  10. <Button Content="测试"></Button>
  11. </Grid>
  12. </my:MyBaseWin>





posted @ 2015-05-03 23:37  阿豪best  阅读(178)  评论(1)    收藏  举报