WPF控件开发的入门引导

如果动态创建WPF控件,动态捕捉控件的事件,以及定义属性等,上图是我学习后的一个效果图,后续会把实现的代码直接贴上来,我相信看代码是众网友的强项。

以下是我的工程文件预览:

App.xaml没动过,是系统生成的。

MainWindow.xaml

[xaml代码]

<Window x:Class="WpfMainApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid Name="grdParent">
        <Button Content="Dynamic Load Wpf Control" Height="36" HorizontalAlignment="Left" Margin="12,263,0,0" Name="button1" VerticalAlignment="Top" Width="228" Click="button1_Click" />
        <Button Content="Set Wpf Control Content" Height="29" HorizontalAlignment="Left" Margin="254,12,0,0" Name="button2" VerticalAlignment="Top" Width="213" Click="button2_Click" />
        <TextBox Height="29" HorizontalAlignment="Left" Margin="12,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="147" />
    </Grid>
</Window>
[CS代码]

下面是控件的代码:

 

EditPlus.xaml

[xaml代码]

<UserControl x:Class="WpfComctl.EditPlus"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300" Name="EditPlusControl">
    <Grid Name="grdRoot"></Grid>
</UserControl>

[CS代码]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值