![](https://img-blog.csdnimg.cn/20190115111013554.jpeg?x-oss-process=image/resize,m_fixed,h_224,w_224)
WPF
记录自己wpf的学习过程
Maybe_ch
从0开始
展开
-
WPF-隐藏窗体标题栏和边框
方法一AllowsTransparency="True" WindowStyle="None"缺点:使用该方法会导致标题栏无法被拖动,可以自我添加boder的形式来重写拖动例如:<Window x:Class="WpfApp.MainWindow" Title="MainWindow" Height="450" Width="800" AllowsTransparency="True"WindowStyle="None"> <Grid> <Border Bac原创 2021-12-10 12:07:35 · 7774 阅读 · 0 评论 -
WPF-界面无边框情况下界面无法拖动和调节大小
<WindowChrome.WindowChrome> <WindowChrome GlassFrameThickness="1" CaptionHeight="30" CornerRadius="0" /> </WindowChrome.WindowChrome>附上官方文档https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.shell.windowchrome?...原创 2020-09-25 17:09:38 · 1005 阅读 · 0 评论 -
WPF-界面等比例自适应
今天在探索WPF响应式时,看到这个方法记录一下只需要在你原有界面套上Viewbox和Canvas,Canvas要设定固定尺寸,这样就可以做一个等比缩小 <Viewbox Stretch="Fill"> <Canvas Width="1920" Height="1080"> 原界面 </Canvas> </Viewbox>弊端字体等也会同时缩小,像图原创 2020-09-24 15:36:38 · 1565 阅读 · 0 评论 -
WPF 滑动条滑动到最下时,界面会发生抖动,界面方法
视图中添加:listview / ScrollViewer /ScrollBar 都可以使用 ManipulationBoundaryFeedback="SCManipulationBoundaryFeedback"逻辑代码添加: private void SCManipulationBoundaryFeedback(object sender, ManipulationBoundar...原创 2019-11-25 14:55:22 · 611 阅读 · 0 评论 -
WPF-实现TextBox和PasswordBox显示背景文字
TextBox实现完成下面的效果 <TextBox Name="userId" CaretBrush="White" Foreground="#ffffff" FontSize="16" BorderBrush="Transparent" BorderThickness="0"> <TextBox.Resources> ...原创 2019-03-22 16:17:12 · 4307 阅读 · 2 评论 -
WPF-效果
<Window x:Class="效果.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://sche...原创 2018-06-25 16:14:32 · 376 阅读 · 0 评论 -
WPF-形状旋转
RenderTransform<Window x:Class="变换与透明.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" ...原创 2018-06-22 17:24:02 · 1666 阅读 · 0 评论 -
WPF-渐变画刷
这里介绍两种渐变画刷,一种是LinearGradientBrush 线性渐变,一种是RadialGradientBrush 圆形渐变LinearGradientBrush线性渐变设置 Offset为颜色的渐变位置范围0-1,渐变起点StartPoint,渐变终点EndPoint=”0,1”<LinearGradientBrush StartPoint="0,0" End...原创 2018-06-22 16:14:53 · 1726 阅读 · 0 评论 -
WPF-SolidColorBrush 画刷
SolidColorBrush单色画刷,Color属性设置其颜色<Window x:Class="画刷.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2...原创 2018-06-22 15:56:16 · 7738 阅读 · 0 评论 -
WPF-形状
WPF-形状<Window x:Class="形状.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="h...原创 2018-06-22 10:59:31 · 327 阅读 · 0 评论 -
WPF-样式Style
Style若我们要给多个控件设置多个相同的属性时,这时一个一个设置会显得很麻烦,这时使用Style给多个控件设置就显得很简便。 如果我要给一个button设置字体大小,字体等内容需要做如下设置 <Window.Resources> <sys:Double x:Key="ButtonFontSize">18</sys:Double&g...原创 2018-06-19 17:22:47 · 339 阅读 · 0 评论 -
WPF-单实例化程序
一、添加引用Microsoft.VisualBasic 二、添加新类,单实例应用程序包装器SingleInstanceApplicationWrapper类,这里我将App.xaml的启动方式删除,使用自己创建的启动代码,下面附上。using System;using System.Collections.Generic;using System.Linq;using System...原创 2018-06-08 11:08:42 · 554 阅读 · 0 评论 -
WPF-父子窗口交互demo
主界面代码,主界面设置两个按钮,Open Window按钮用于打开新窗口,Update用于更新打开的新窗口中的数据<Window x:Class="windo.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schem...原创 2018-06-08 10:52:20 · 2639 阅读 · 0 评论 -
WPF-ListBox
这里还是使用一个demo来展示ListBox的使用,这里是用LIstBox嵌套CheckBox,使用ListBox的SelectionChanged事件来实时告诉使用者选中了那个复选框,是true还是false。并最后有统计按钮,统计总共选了那些复选框。<Window x:Class="list.MainWindow" xmlns="http://schemas.micr...原创 2018-06-07 15:58:13 · 1204 阅读 · 0 评论 -
WPF-Expander
Expander <Expander Header="Expander" Margin="5" ExpandDirection="Up"> <Grid> <Button Content="Button"/> </Grid&g原创 2018-06-07 10:03:01 · 1491 阅读 · 2 评论 -
WPF-TabControl 选项卡
TabControl 我使用一个小的demo来对TabItem进行讲解,先进行视图的设置,通过如下的代码设置可以达到下图的效果。<Window x:Class="TitleControl.tabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x=...原创 2018-06-07 09:48:22 · 21398 阅读 · 3 评论 -
WPF-Button|IsCancel&&IsDefault
Button个别属性<Button ToolTip="ESC" IsDefault="True" IsCancel="True" Name="capture" Grid.Row="1" Click="Button_Click">IsCancel属性设置为true时会绑定键盘ESC,按下ESC键相当于点击该button。 IsDefault获取或设置一个原创 2018-06-07 09:13:51 · 2133 阅读 · 0 评论 -
WPF-鼠标移动事件demo
鼠标事件 MouseEnter鼠标指针移动到该元素上时 MouseLeave鼠标指针离开该元素时 MouseEnter、MouseLeave都是直接事件,不会发生冒泡。 PreviewMouseLeftButtonDown按下鼠标左键 PreviewMouseRightButtonDown按下鼠标右键 PreviewMouseRightButtonDown...原创 2018-06-06 17:13:48 · 4174 阅读 · 0 评论 -
WPF-键盘事件
通过一个demo来了解键盘事件 设计代码&lt;Window x:Class="keyboard.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&原创 2018-06-06 15:53:02 · 987 阅读 · 0 评论 -
WPF-Grid使用
Grid设置行和列Grid.RowDefinitionsGrid.RowDefinitions用于设置行数量,在<Grid.RowDefinitions></Grid.RowDefinitions>的标签中添加 <RowDefinition></RowDefinition>元素,有几个<RowDefinition></R...原创 2018-06-06 10:42:23 · 8149 阅读 · 2 评论 -
WPF-组合使用Panel
组合使用Panel代码可到达如下效果<Window x:Class="combination.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"...原创 2018-06-06 09:07:17 · 1749 阅读 · 0 评论 -
WPF-DockPanel
WPF中的DockPanel是提供对元素进行左边停靠、右边停靠、顶部停靠、底部停靠、填充停靠操作的布局控件,通过设置DockPanel.Dock属性决定元素的停靠位置,LastChildFill属性默认为false,若设置为true最后一个元素将布满整个Panel。下面代码的效果如下<Window x:Class="DocPanl.MainWindow" xmlns="h...原创 2018-06-06 08:47:49 · 1005 阅读 · 0 评论 -
WPF-StackPanel面板
StackPanelOrientation属性 Orientation属性决定SatckPanel中元素的排列方向,默认为垂直排列 Orientation=”Vertical”&amp;amp;lt;Window x:Class=&amp;quot;StackPanel.MainWindow&amp;quot; xmlns=&amp;quot;http://schemas.microsoft.com/win原创 2018-06-05 16:37:29 · 9098 阅读 · 1 评论 -
WPF-Bingding的数据校验
在进行数据校验时,我们需要用到ValidationRule类,ValidationRule类是一个抽象类,在使用的时候我们需要创建它的派生类并实现它的Validate方法,Validate方法的返回值是ValidationResult类型对象,如果校验通过就把ValidationResult对象的IsValid属性设置为true,反之设为false并为ErrorContent属性设置一个消息内容。...原创 2019-01-14 18:52:54 · 382 阅读 · 0 评论 -
WPF-数据绑定
下面记录了几种数据绑定时的场景,以供之后自己参考。一、Path=.的Binding这是数据绑定中的特殊情况,Binding源本身就数据且不需要Path来指明,string、int等基本数据。&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006...原创 2019-01-14 15:22:42 · 1981 阅读 · 2 评论 -
WPF实现简单的数据绑定
创建数据源类首先创建一个作为数据源来使用,这里创建的类需要实现System.ComponentModel名称空间中的INotifyPropertyChanged接口。当为Binding设置了数据源之后,Binding就会自动侦听来自这个接口的PropertyChanged事件。 class Student:INotifyPropertyChanged { public ...原创 2019-01-09 17:33:45 · 477 阅读 · 1 评论 -
WPF打开子窗口给父窗口添加蒙版效果
打开子窗体这是打开子窗体的代码,注释比较详细供大家参考private void Button_Click(object sender, RoutedEventArgs e) { EditGateLIst gatel = new WpfApplication1.EditGateLIst();//这是我要打开的新窗体 //蒙板 ...原创 2018-12-21 14:17:33 · 2266 阅读 · 2 评论 -
WPF打开Windows和Page的方法
打开Page NavigationWindow window = new NavigationWindow(); window.Source = new Uri("Page1.xaml", UriKind.Relative); window.Show();打开Windows EditGateLIst...原创 2018-12-21 14:10:15 · 6295 阅读 · 4 评论 -
WPF鼠标事件汇总
下面列举常用的鼠标事件:事件触发条件MouseLeave鼠标离开控件时发生MouseEnter鼠标进入控件时发生MouseMove鼠标移动过程中重复发生MouseDown鼠标键按下时发生MouseLeftButtonDown鼠标左键按下时发生MouseRightButtonDown鼠标右键按下时发生MouseUp鼠标键松开时发...原创 2018-12-20 19:17:18 · 5616 阅读 · 0 评论