1.wpf以xml实现界面的定义
xml语句直接定义控件的排列
<Window x:Class="WpfApplication1.窗口名"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
.............. //可以在其中定义背景,各种控件
</Grid>
</Window>
比如:
<Grid.Background>
<LinearGradientBrush>
<GradientStop Offset="0" Color="Blue"></GradientStop>
<GradientStop Offset="0.5" Color="LightBlue"></GradientStop>
</LinearGradientBrush>
</Grid.Background>
<TextBox Height="23" Margin="10,10,10,0" Name="textBox1" VerticalAlignment="Top" Text="{Binding ElementName=slider1, Path=Value, UpdateSourceTrigger=PropertyChanged}" />
<Slider Height="21" Margin="10,40,10,0" Name="slider1" VerticalAlignment="Top" Maximum="100" />
2.文件介绍
App.xaml.cs:整个项目程序的属性.相当于vc中的myApp.cpp
MainWindow.xaml.cs:主窗口的cpp
bin:编译输出目录
obj:链接输出目录
3.WPF命名空间以System.Windows开头.
System.Windows.Controls:控件的类
System.Windows.Media:关于绘图,画刷,视频,音频的类
System.Windows.Forms:是Window Form编程相关的类
System.Windows.Freezable:很多内容,画刷,时间线,几何等
System.Object是所有.net的父类
4.像这样的:xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"只是声明命名空间,而不是网址,般都要引用这两句
WPF命名空间:xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
XAML命名空间:xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" (以x开头)
XAML规定最少要有一个XML的命名空间.一般放在根元素中.
WPF根元素有4种:<Window>,<Page>,<Application>,<ResourceDictionary>
5.标签是配套的,<Grid></Grid>,也可以直接用/,比如:<Grid/>,前提是它中间没有包含其他控件.
要使用控件,必须在开头先用using声明,省得每次引用要一大堆来源.
6.在wpf默认是没有System.Window.Forms或System.Draw的.如果需要可以在解决方案浏览器->引用->右击->添加引用
在.NET一栏,选中System.Window.Forms或System.Draw,就可以了.
不过System.Window.Forms可能与WPF有冲突,会提示是否引用System.Windows.Input还是System.Window.Forms
这时需要明确指定:private void Window_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
7.判断鼠标按钮是否按下:
private void grid1_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (e.LeftButton==MouseButtonState.Pressed) //或者.Released
{
}
}