天天看点

WPF五分钟入门

不知道什么原因,我的专业方向总是不停变换,虽然工作很稳定。

c++ builder->asp.net->java->C# winform->vc->cad二次开发->revit二次开发

我老是不得不学习新东西,才能完成任务。

做Revit开发界面很要紧,WPF很需要。

好在我有div+css基础,并且做过一些时间Silverlight

现在才发现学过的东西早晚能用上,xml和linq在revit开发中也很常用。

啥都会啥也不精,这是本人的状态,希望大家不要像我。

今天先把WPF入个门。

WPF五分钟入门

打开VS2010新建一个WPF应用程序。

WPF主要为了随意控件windows控件的位置,显示比较炫的界面。

注意两点。

1.界面控制,类似div+css

通过margin,padding,background来显示复杂界面。

<Grid>类似<table>

2.事件响应、程序启动跟普通windows开发类比学习。

2.1没有main()函数,

继承自System.Windows.Application的App类相当于那个包含Main()的Program.cs

打开App.xaml在StartupUri属性里设置启动窗体

2.2事件响应和普通windows开发没什么区别。

2.3用户控件和windows用户控件也没什么区别。

代码:

MainWindow.xaml

<Window x:Class="WpfApp.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="http://dotnet.5d6d.com" Height="350" Width="525">

    <Grid>

        <Grid.RowDefinitions>

            <RowDefinition Height="50"></RowDefinition>

            <RowDefinition Height="30"></RowDefinition>

        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="100"></ColumnDefinition>

            <ColumnDefinition Width="150"></ColumnDefinition>

        </Grid.ColumnDefinitions>

        <TextBox Name="txtValue" Grid.Row="0" Grid.Column="0" Margin="5,10,8,3"></TextBox>

        <Button Name="btnOk" Grid.Row="1" Grid.Column="1" Width="100" Height="20" Click="btnOk_Click">ok</Button>

    </Grid>

</Window>

App.xaml

<Application x:Class="WpfApp.App"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

             StartupUri="MainWindow.xaml">

    <Application.Resources>

    </Application.Resources>

</Application>

继续阅读