WPF:基础知识

mac2022-06-30  26

 WPF:1、数据驱动 2、UI定义与运行逻辑分离

一、

  1、编译

      /t:exe 命令行程序;/t:winexe 图形用户界面程序;/t:library 动态链接库

  2、启动

    1)编译后生成的App.g.cs中默认生成了main函数,并运行App类

/// <summary> /// Application Entry Point. /// </summary> [System.STAThreadAttribute()] [System.Diagnostics.DebuggerNonUserCodeAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")] public static void Main() { WpfChapter01.App app = new WpfChapter01.App(); app.Run(); } View Code

    2)App.xaml文件中StartupUri="MainWindow.xaml"语句是启动MainWindow窗体。因此,启动后呈现的界面是MainWindow界面(自定义)。

    3)自定义main函数:右击解决方案内的App.xaml文件,选择Properties(属性),Build Action(生成操作) 从默认ApplicationDefinition改为Page。

      自定义Main函数如下:

/// <summary> /// App.xaml 的交互逻辑 /// </summary> public partial class App : Application { [STAThread] public static void Main() { WpfChapter01.App app = new WpfChapter01.App(); app.InitializeComponent(); app.Run(); } } View Code

   3、解析Xaml文件(xaml是声明性语言,xaml编译器为每个标签创建一个与之对应的对象)

    因为xaml文件被解析为x:class所赋值的类名,而这个类名默认情况下与其自身的xaml.cs同名,故xaml.cs中类名使用了patial关键词。

    1)、x:Class是告诉窗口要编译成说明类,x:ClassModifier把类指定为怎么样的访问权限;编译器把x:Name编译成类的属性;x:FieldModified设置属性的访问级别;x:Key资源放到资源字典里,通过Key来检索; x:shared声明资源是否共享,一定要和x:key配合使用,当设置为 false 时,会修改 WPF 资源检索行为,以便特性化资源请求为每个请求创建一个新实例,而不是所有请求共享同一个实例。

      2)、Xaml文档树形结构(协助操作类:VisualTreeHelper 、LogicalTreeHelper)

    3)、Xaml中属性赋值:简单使用字符串(借助TypeConvert类、TypeConvertAttribute类派生类转换,重写ConvertFrom函数,并把TypeConvertAttribute[typeof(ChildTypeConvertClass)])放在目标类上面,即绑定到目标类上、复杂使用属性元素(属性嵌套、罗列)(this.属性名=)

转载于:https://www.cnblogs.com/shenchao/p/5602663.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)