Wpf 基础1

wpf 控件分类

按钮(Buttons): Button, RepeatButton
对话框(Dialog Boxes):打开文件对话框OpenFileDialog, 打印对话框PrintDialog, 文件保存对话框SaveFileDialog
数字化墨水(Digital Ink): 墨水面板InkCanvas,墨迹呈现器InkPresenter
文档(Documents): DocumentViewer, FlowDocumentPageViewer, FlowDocumentReader, FlowDocumentScrollViewer, StickyNoteControl
输入框(Input): TextBox, RichTextBox, PasswordBox
版面布局(Layout): Border, BulletDecorator, Canvas, Panel, DockPanel, WrapPanel,VirtualizingStackPanel,StackPanel, Expander, Grid, GridView, GridSplitter, GroupBox, ResizeGrip, Separator, ScrollBar, ScrollViewer, Thumb, Viewbox, , Window
媒体(Media): Image, MediaElement, SoundPlayerAction
菜单(Menus):Menu, ContextMenu, ToolBar
导航(Navigation):Frame, Hyperlink, Page, NavigationWindow, TabControl
选择(Selection):CheckBox, ComboBox, ListBox, TreeView, RadioButton, Slider
用户信息(User Information): AccessText, Label, Popup, ProgressBar, StatusBar, TextBlock, ToolTip

一些控件中还可以包含更多的其他控件或对象[即所谓的“富内容(Rich Content)”]:
例如:一个Label可以包含如文字、图像,面板(Panel)等任何其他对象。下面类型控件都支持这种“更丰富的包含”:
ContentControl: Window, Frame, ListBoxItem, GroupItem, Label, ScrollViewer, ToolTip, UserControl, StatusBarItem, Button等
ItemsControl: ListBox, HeaderedItemsControl,TreeView,Menu,Selector,StatusBar
HeaderedContentControl: TabItem, GroupBox, Expander
HeaderedItemsControl: MenuItem, TreeViewItem, ToolBar

命名空间

以下2个必须存在

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

引用命名空间

同dll

xmlns:Converter ="clr-namespace:NMS.MR.App.Exam.ExamCard.ExamCatalog.ValueConverter"

不同dll

xmlns:CommondUi="clr-namespace:NMS.MR.Common.UI;assembly=NMS.MR.Common.UI"

wpf应用程序结构

App.config --配置文件

App.xaml--设置启始文件和资源文件

MainWindow.xaml--窗体

启动生命周期

SourceInitialized(资源初始化完毕) - Activated 获得焦点 (首次打开软件时;由别的软件切换回当前软件时;点击当前软件在任务栏的按钮时)- 

Loaded (初始化完成)- ContentRendered(窗口没有内容不会触发)

如果您使用数据绑定,则需要使用ContentRendered事件。

Deactivated和Activated 相对 一个丢失焦点一个获得焦点

关闭生命周期

Closing( 准备关闭,可以取消关闭) - Deactivated(丢失焦点) - Closed()关闭

设置启动页

1.StartupUri="MainWindow.xaml"

2.App.xaml中增加 Startup事件

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();
            Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose; // 关闭最后一个
            Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose; // 关闭主窗口
        }
3. Application.Current.StartupUri          
      Application.Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);
Window的一些属性
      WindowStartupLocation - 启动的位置  (CenterScreen居中 Manual 默认)
      WindowState - 启动的状态 (Maximized 最大化 Minimized 最小化 Normal 默认)
      ResizeMode- 窗口大小改变模式 (

 NoResize。用户无法调整窗口的大小。不显示最小化框和最大化框。

CanMinimize。用户只能最小化窗口以及从任务栏还原窗口。同时显示最小化框和最大化框,但只有最小化框处于启用状态。

CanResize。用户完全能够使用最小化框和最大化框以及一个环绕窗口的可拖动轮廓来调整窗口大小。显示并启用最小化框和最大化框。(默认值)。

CanResizeWithGrip。此选项的功能与 CanResize 相同,但在窗口右下角添加了一个“大小调整手柄”。

1. 控件解析
1.1 Border 
一个边框 常用属性
BorderThickness="2"
BorderBrush="Red"
Margin="100,100,100,100"
HorizontalAlignment="Center"
VerticalAlignment="Center"
CornerRadius="50"
Width="100"
Height="100"
 

 

posted @ 2020-09-09 17:02  wujh123  阅读(91)  评论(0)    收藏  举报