首页 > Windows开发 > 详细

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

时间:2015-05-04 01:02:38      阅读:587      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!