.NET-7.WPF学习1. 经验总结

系列文章目录


前言

下面的几个就足够熟悉了。好好学习,落到实处。
查看以下的地址就好了。

参考链接

学习参考

官方文档参考项目11
我的Blog Wpf画图工具动画11-22
官网组件的查看流程图1122温度区域测量
官方文档思维导图
wpf教程MVVM框架UI控件
WPF TutorialPrism-文档HandyControl-11
WPF从零到1教程详解CommunityToolkit.MvvmMaterialDesignInXAML
B站痕迹-git-MyToDoAppCaliburn.Micro官网-git11-22-33-44-55-66-77-88
cnblog系列文章MVVMLight官网-好文
项目案例CM11-22-33
111-222-333CTM11-22-33-44
wpf模板-11-22PRhyui-Smp-11-22
TerminalMACS
dotnet9
随记好文
WPF使用转换器(Converter)控件共用事件
自定义控件 极力推荐gitHubTopicwpf
千自学
码客
独立观察员

git 项目提交

1. 在git或gitee 上建一个项目,克隆到本地上.
2. 将代码 copy 到 本地的文件夹src下面来
3. git add . //将所有文件添加到暂存区
4. git commit -m "输入此次提交的解释" //-m 注释
5. git push origin master  //提交远程分支
//其他操作
git pull //拉取
git status   //查看当前状态 (红色代表有变化)
git reset --hard commit_id。//退回某个版本
git diff <文件>//顾名思义就是查看difference
git reflog //用来记录你的每一次命令查看命令历史
git branch -a //查看分支
git branch zy // 创建分支
git checkout zy //切换分支 
git checkout -b zy(分支名) //创建分支zy,同时切换该分支
git help <command> //查看命令
git log //查看提交历史记录
git clone // 克隆到本地上

git config --global user.name "bettyaner"
git config --global user.email bettyaner@163.com
- git中有两个状态:内容状态和文件状态,
内容状态标示内容文件的改变,有三个区域:工作目录,暂存区和提交区
文件状态有两个状态:已跟踪和未跟踪

wpf理论

//主要知识点
布局、控件、样式、依赖属性、资源、触发器、模板、数据绑定mvvm command
//MVVM开发模式框架、
(prism ,MVVMLight ,CommunityToolkit.Mvvm,Microsoft.Toolkit.Mvvm ,Caliburn.Micro(简称CM)) --fody

//六大布局:
StackPanel,WrapPanel,DockPanel,Grid,UniformGrid,Canvas

//五大触发器: 
Trigger 、MultiTrigger、DataTrigger、 MultiDataTrigger、 EventTrigger 
每个触发器都是 System.Windows.TriggerBase的派生类实例, 

//五种绑定:
Default、OneTime、OneWay、TwoWay、OneWayToSource

//基本的公共样式,继承,静态资源与动态资源:
Resources>Style(key,TargetType,BasedOn)>Setter
StaticResource,DynamicResource
<SolidColorBrush x:Key="solidColor" Color="Red"/>
this.Resources["solidColor"]=new SolidColorBrush(Colors.Yellow);

//获得控件元素:e.Source as Button;(FrameworkElement) sender;(FrameworkElement) args.Source;
// Grid 分割栏 GridSplitter 
//什么时xaml?xaml 是wpf中专门用来设计ui的语言。
//panel.Zindex 越大越在上面
//UpdateSourceTrigger三个值:Explicit、LostFocus和PropertyChanged。
//折叠所有XAML代码节CTRL + M,L  两次;CTRL + M, A
//一个竖线
<Line Height="15" Y2="1" Stroke="#707070" Stretch="Uniform" Margin="6 0" />
// 后台代码更改字体或者背景颜色
new SolidColorBrush( Color.FromArgb(255, 255, 0, 0));
new SolidColorBrush((Color)ColorConverter.ConvertFromString("#92e492"));
new SolidColorBrush(Color.FromRgb(255,255,255));
Brushes.Green;
//ScrollViewer 
VerticalScrollBarVisibility HorizontalScrollBarVisibility CanContentScroll="True"
//TextBox多行文本框
<TextBox Height="373" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"></TextBox>
//图标的赋值
Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/DrawTools;component/Images/file.ico")).Stream;
treeViewItem.Icon = new System.Drawing.Icon(iconStream);  // 图标
//image.Source
Image image = new Image(); image.Width = 850; image.Stretch = Stretch.Fill;
BitmapImage picture = new BitmapImage(new Uri(lbi));
image.Source = picture;
//设置回车 设置ESC
<Button Name="btnDefault" IsDefault="true" Click="OnClickDefault">OK</Button>设置回车
<Button Name="btnDefault" IsCancel="true" Click="OnClickDefault">OK</Button>设置ESC
//mvvm 命令 其他事件
Nuget包:Microsoft.Xaml.Interactions 
<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseDoubleClick">
        <i:InvokeCommandAction Command="{Binding Btncommand}"  CommandParameter="read" />
    </i:EventTrigger>
</i:Interaction.Triggers>
//pack WPF URI
pack://application:,,,/是协议;“,,,”是“///”的变体
Uri uri = new Uri("pack://application:,,,/ResourceFile.xaml", UriKind.Absolute);
// ClickMode="Hover" Press Release
<Button Content="ClickMe" Click="OnClick1" ClickMode="Hover"/>
void OnClick1(object sender, RoutedEventArgs e)=> btn1.Background = Brushes.LightBlue;
// CommandParameter绑定Path后为"."或者空表示绑定source本身

 
1.代码摘抄 
public static class Win32Helper
{
    [DllImport("shell32.dll")]
    public static extern int ShellAbout(IntPtr hWnd, string szApp, string szOtherStuff, IntPtr hIcon);
}

private void OnAboutCommand()
{
    Assembly assembly = Assembly.GetExecutingAssembly();
    var title = assembly.GetCustomAttribute(typeof(AssemblyTitleAttribute)) as AssemblyTitleAttribute;
    var version = assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)) as AssemblyFileVersionAttribute;

    StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("WpfNotepad.ico", UriKind.Relative));
    Icon icon = new Icon(streamResourceInfo.Stream);

    Win32Helper.ShellAbout(Process.GetCurrentProcess().MainWindowHandle, title.Title, version.Version, icon.Handle);
}

private void OnFeedBackCommand()
{
    Process.Start("feedback-hub://?appid=1231313");
}

private void OnHelpCommand()
{
    Process.Start("https://go.microsoft.com/fwlink/?LinkId=834783");
}

# C#之AOP的实现
1.什么是AOP
AOP(Aspect Oriented Programming)的字面意思是“面向切面编程”。举个例子解释一下,如果我们把三层架构的表现层,业务逻辑层和数据访问层看作是河流的上游,中游和下游,那么“面向切面编程”就是架设在上游和中游分界处的三峡大坝,他对每一滴河水作一个公共的操作,比如染成红色或者过滤掉大鱼。
AOP的意义在于能够让我们在不影响原有功能的前提下,为软件横向扩展功能,说穿了就是解耦。
https://www.cnblogs.com/panpanwelcome/p/8617552.html

2. 任务调度:
这个任务每天或每周自动执行,定时刷新数据。
Coravel、Quart.Net、HangFire.

3.  WPF中怎样拖拽文件呢?
注册这两个事件即可:DragEnter、Drop
<Grid   AllowDrop="True" Drop="Grid_Drop" DragEnter="Grid_DragEnter">
 private void Grid_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.FileDrop))
        e.Effects = DragDropEffects.Link;
    else
        e.Effects = DragDropEffects.None;
}
private void Grid_Drop(object sender, DragEventArgs e)
{
    //需要获取目标文件路径
    var fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
    zhouyi.Content = fileName;
}

4. c#中类的执行顺序
1子类静态成员2子类静态构造3子类实例成员4父类静态成员
5父类静态构造6父类实例成员7父类实例构造8子类实例构造

5. goto 控制程序跳转到指定的位置执行
提示:goto 语句并不限于在循环中使用,其它的情况也可以使用。但是,goto 语句不能从循环外跳转到循环语句中,而且不能跳出类的范围。
login:
Console.WriteLine("请输入密码");var userpwd = Console.ReadLine();
goto login;

6. C#中refoutin的区别与使用
refoutin都是将参数按引用来传递,什么都不加是值传递,这在内存分配上是有差异的。
ref:可读可写(可进可出)
out:只能写不能读(只出不进)
in:只能读不能写(只进不出)

7. 值传递、引用传递、输出传递(值传递是将参数传递给函数的默认方式)
值传递:值传递的本质就是将实参的副本(将实参的值复制一份)传递给函数的形参。认方式
引用传递:引用传递是对变量内存位置的引用。

8. C# 中的析构函数
同样是类中的一个特殊成员函数,主要用于在垃圾回收器回收类实例时执行一些必要的清理操作。
class Car
{
    ~Car()  // 析构函数
    Console.WriteLine("类中的析构函数");
}

9. 使用 this 关键字串联构造函数
//先执行 Test(),后执行 Test(string text)
Test test = new Test("测试数据");
public class Test
{
    public Test(){ Console.WriteLine("无参构造函数");}
    public Test(string text) : this()
    {Console.WriteLine(text+"实例构造函数");}
}

10. this关键字(niubi)
1) 使用 this 表示当前类的对象
2) 使用 this 关键字串联构造函数
3) 使用 this 关键字作为类的索引器
4) 使用 this 关键字作为原始类型的扩展方法

11. 通过委托传值,触发,值得参考。
public class PublisherDemo
{/***********发布器类***********/
    private string myVar;
    public static Action<string> ChangeValue;
    public string MyVar
    {
        get => myVar;
        set { myVar = value; ChangeValue(value); }// 发事件
    }

}
public class SubscriberDemo
{/***********订阅器类***********/
     public SubscriberDemo()
            PublisherDemo.ChangeValue+=(obj)=>{};
}

12. *.Parse(string)*.TryParse(string,out int demo)
注意:ConvertToInt32()int.Parse()对于空值(null)的处理不同,ConvertToInt32(null)会返回0而不会产生任何异常,但int.Parse(null)则会产生异常。
Console.WriteLine(Int32.Parse("22"));
Int32.TryParse("33", out int demo);
Convert.ToInt32(null)

13.  
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));//转化成24小时
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));//转化成24小时

14. FlowDocumentReader滚动到顶部
FlowDocumentPageViewer1.Document.BringIntoView();

15. 
这似乎很适合页面浏览,但不适用于滚动视图,这没关系。
reader的类型是FlowDocumentReader,文档是其中的FlowDocument。
设置的书签:

var paginator = ((IDocumentPaginatorSource)document).DocumentPaginator as DynamicDocumentPaginator; 
var position = paginator.GetPagePosition(paginator.GetPage(reader.PageNumber - 1)) as TextPointer; 
bookmark = position.Paragraph; 
还原书签:

bookmark.BringIntoView(); 

理论的链接

16. WPF使用阿里巴巴iconfont矢量图标库
http://t.zoukankan.com/Stay627-p-14469662.html
17. 读取appsetting.json的两种方式
https://www.modb.pro/db/104729
18. WPF模拟点击按钮
btn.RaiseEvent(new RoutedEventArgs(Button.ClickEvent, btn));
19. 关于c#:将List < T >转换为ObservableCollection < T >
https://www.codenong.com/16432450/
20..NET/C#面试手册》
https://www.yuque.com/zhanglin-l1ak6/ll06t7
21. 中国有哪些比较出名的C#大佬。?
https://www.cnblogs.com/sexintercourse/p/16256753.html
22. ECMAScript 6 入门
https://es6.ruanyifeng.com/#docs/object-methods
23. .Net Core Excel导入导出神器Npoi.Mapper
https://www.cnblogs.com/wucy/p/14125392.html
https://donnytian.github.io/Npoi.Mapper/
24. MiniExcel
https://gitee.com/dotnetchina/MiniExcel#getstart1
25. c# 获取照片的经纬度和时间
https://blog.csdn.net/fangyu723/article/details/102820203

控件介绍

  1. (基本)Border 、TextBlock、TextBox 、RichTextBox 、PasswordBox
  2. (按钮)Button 、RadioButton 、RepeatButton
  3. (布局)Grid、DockPanel、StackPanel、WrapPanel、Panel
  4. (数据显示)DataGrid、ListView、TreeView
  5. (菜单)ContextMenu、Menu、ToolBar
  6. (日期)Calendar、DatePicker
  7. (导航) Frame、Hyperlink、Page、NavigationWindow、TabControl
  • Frame 框架是一种支持导航的内容控件。
  • Hyperlink 提供用于在流内容中承载超链接的功能的内联级别的流内容元素。
  • Page 封装一页可由 Windows Internet Explorer、NavigationWindow 和 Frame 导航到和承载的内容
  • NavigationWindow 表示支持内容导航的窗口。
  • TabControl 表示包含多个项的控件,这些项共享屏幕上的同一空间。
  • Calendar 代表一个控件,此控件允许用户使用可视的日历显示来选择日期。
  • DatePicker 表示一个允许用户选择日期的控件
  • ContextMenu 表示一个弹出菜单,该弹出菜单使控件能够公开特定于该控件的上下文的功能。
  • Menu 表示一个 Windows 菜单控件,该控件可用于按层次组织与命令和事件处理程序关联的元素。
  • ToolBar 为一组命令或控件提供容器。
  • DataGrid 表示用于在可自定义的网格中显示数据的控件
  • ListView 表示用于显示数据项列表的控件
  • TreeView 表示一个控件,该控件在树结构(其中的项可以展开和折叠)中显示分层数据。
  • Grid 定义由列和行组成的灵活的网格区域
  • DockPanel 定义一个区域,从中可以按相对位置水平或垂直排列各个子元素
  • StackPanel 将子元素排列成水平或垂直的一行
  • WrapPanel 按从左到右的顺序位置定位子元素,在包含框的边缘处将内容切换到下一行
  • Panel 为所有 Panel 元素提供基类
  • Border 在另一个元素四周绘制边框和/或背景。
  • TextBox 表示一个控件,该控件可用于显示或编辑无格式文本。
  • RichTextBox 支持更丰富内容
  • PasswordBox有关需要接受密码或其他敏感输入
  • RepeatButton表示从按下按钮到释放按钮的时间内重复引发其 Click 事件的控件

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

joyyi9

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值