wpf学习笔记(1)《都是自己根据网络资源学习记录的仅供参考》

来源:互联网 发布:重庆工商网络教务系统 编辑:程序博客网 时间:2024/05/16 02:08

 一直不想写blog但是发现光看别人的有种愧疚感,现在开始把自己学习winFX的笔记写出来供大家一起学习。
winfx就是.net 3.0,包括wpf、wcf、wwf。(个人理解)
其他的不说,看个例子先:

  1. 建立一个wpf的工程。
  2. 打开window1.xaml文件,在xaml代码中写入以下代码:
<Window x:Class="FullWPFWCFWWF.Window1"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    Title
="FullWPFWCFWWF" Height="300" Width="300"
    
>
    
<Grid>
      
<Button Name="MyButton" HorizontalAlignment="Center" VerticalAlignment="Center"
               Width
="100" >确定</Button>
    
</Grid>
</Window>

看设计器多了个按钮@_@!

我们来增加个按钮的点击事件.

<Button Name="MyButton" HorizontalAlignment="Center" VerticalAlignment="Center"
               Width
="100" Click="ButtonOnClick">确定</Button>


好了前台事件注册了,后台加入代码:

    public partial class Window1 : System.Windows.Window
    
{
        
public Window1()
        
{
            InitializeComponent();
        }

        
void ButtonOnClick(object sender, RoutedEventArgs args)
        
{
            MessageBox.Show(
"我出现了");
        }

    }

启动调试看下.
ok第一个小例子写成了。
HorizontalAlignment="Center" VerticalAlignment="Center" 这两句代表的是按钮的位置.我们设置成窗体的中间位置.
原创粉丝点击