码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-05-04 01:03:16      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:

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>





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

标签:

原文地址:http://www.cnblogs.com/ahaobest/p/4475057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!