WPF - 项目样例

news/2024/10/14 18:36:13

WPF - 项目样例

 1. 创建项目:

参考:https://www.cnblogs.com/1285026182YUAN/p/18462396

 

2. 修改App.xaml

<Application x:Class="ModelFileMigrate.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="clr-namespace:ModelFileMigrate"><Application.Resources><ResourceDictionary><ResourceDictionary.MergedDictionaries><ResourceDictionary><local:Bootstrapper x:Key="bootstrapper"/></ResourceDictionary></ResourceDictionary.MergedDictionaries></ResourceDictionary></Application.Resources>
</Application>

 

3. 根目录下 创建Bootstrapper.cs文件

using Caliburn.Micro;
using ModelFileMigrate.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;namespace ModelFileMigrate
{public class Bootstrapper : BootstrapperBase{public Bootstrapper(){Initialize();}protected override async void OnStartup(object sender, StartupEventArgs e){await DisplayRootViewForAsync<ShellViewModel>();}}
}

 

 

4. 创建 views文件夹 ,创建 ShellView.xaml 文件

<Window x:Class="ModelFileMigrate.Views.ShellView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:ModelFileMigrate.Views"xmlns:cal="http://www.caliburnproject.org"mc:Ignorable="d"Title="模型迁移" Height="620" Width="800"><StackPanel ><StackPanel Orientation="Horizontal"><Label Margin="10" Width="80">目标路径:</Label><TextBox Margin="10" Width="620" Text="{Binding Path=PathTarget}"></TextBox></StackPanel><StackPanel Orientation="Horizontal"><Label Margin="10" Width="80">源路径:</Label><TextBox Margin="10" Width="620" Text="{Binding Path=PathSource}"></TextBox></StackPanel><StackPanel Orientation="Horizontal"><Label Margin="10" Width="80">临时路径:</Label><TextBox Margin="10" Width="620" Text="{Binding Path=PathTemp}"></TextBox></StackPanel><StackPanel Orientation="Horizontal"><StackPanel Orientation="Horizontal" Width="260"><Label Margin="10" Width="100" Foreground="red" FontSize="16">总数量:</Label><TextBox Margin="10" Width="80" Foreground="red" FontSize="16" Background="White" BorderBrush="White" Text="{Binding Path=ConAll}" IsReadOnly="True" ></TextBox></StackPanel><StackPanel Orientation="Horizontal" Width="260"><Label Margin="10" Width="80" Foreground="Green" FontSize="16">移动数量:</Label><TextBox Margin="10" Width="80" Foreground="Green" FontSize="16" Background="White" BorderBrush="White"  Text="{Binding Path=ConWait}" IsReadOnly="True" ></TextBox></StackPanel><StackPanel Orientation="Horizontal" Width="260"><Label Margin="10" Width="80" Foreground="red" FontSize="16">剩余数量:</Label><TextBox Margin="10" Width="80" Foreground="Green" FontSize="16" Background="White" BorderBrush="White"  Text="{Binding Path=ConComplete}" IsReadOnly="True" ></TextBox></StackPanel></StackPanel><StackPanel Orientation="Horizontal"><Button x:Name="btn_start" Margin="10" Height="29" Width="72" Background="#FF02F102" cal:Message.Attach="[Event Click]=[Action MoveStart()]" IsEnabled="{Binding ButtonEnabled}">Start</Button><Button x:Name="btn_stop"   Margin="10"  Height="29" Width="72" Background="#FFFFDE00"cal:Message.Attach="[Event Click]=[Action MovePause()]" >Pause</Button></StackPanel><StackPanel Orientation="Horizontal" ><ListView  Margin="10" Height="320" Width="750"   ItemsSource="{Binding LvDataList}" Grid.Row="1" ><ListView.ItemTemplate><DataTemplate><TextBlock Text="{Binding}" /></DataTemplate></ListView.ItemTemplate></ListView></StackPanel></StackPanel></Window>

 

 

5. 创建 ViewModels 文件夹,创建 ShellViewModel.cs 文件

using Caliburn.Micro;
using ModelFileMigrate.Auxiliary;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;namespace ModelFileMigrate.ViewModels
{public class ShellViewModel : Screen, INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged;protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}private double _conAll = 0;public double ConAll{get { return _conAll; }set { _conAll = value; NotifyOfPropertyChange(); }}private double _conWait = 0;public double ConWait{get { return _conWait; }set { _conWait = value; NotifyOfPropertyChange(); }}private double _conComplete = 0;public double ConComplete{get { return _conComplete; }set { _conComplete = value; NotifyOfPropertyChange(); }}private string _pathTarget = @"D:\\aab";public string PathTarget{get { return _pathTarget; }set { _pathTarget = value; NotifyOfPropertyChange(); }}private string _pathSource = @"D:\\aaa";public string PathSource{get { return _pathSource; }set { _pathSource = value; NotifyOfPropertyChange(); }}private string _pathTemp= @"D:\\aac";public string PathTemp{get { return _pathTemp; }set { _pathTemp = value; NotifyOfPropertyChange(); }}private ObservableCollection<string> _lvDataList = new ObservableCollection<string>();public ObservableCollection<string> LvDataList{get { return _lvDataList; }set { _lvDataList = value; OnPropertyChanged(); }}private bool _buttonEnabled = true;public bool ButtonEnabled{get { return _buttonEnabled; }set{_buttonEnabled = value;OnPropertyChanged(nameof(ButtonEnabled));}}public void MoveStart(){ButtonEnabled = false; // 按钮被点击后设置为不可用var InsertLvInfo = (string str) => { LvDataList.Insert(0, str); };var SetConAll = (int val) => { ConAll = val; };var SetConWait = (int val) => { ConWait = val; };var SetConComplete = (int val) => { ConComplete = val; };          new FileOperation().MoveStart(PathSource,PathTarget,PathTemp, InsertLvInfo, SetConAll,SetConWait,SetConComplete);             }public void MovePause() { }}
}

 

 

 6. 创建 文件夹 Auxiliary,创建 文件 FileOperation.cs 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;namespace ModelFileMigrate.Auxiliary
{public class FileOperation{public void MoveStart(string dirPathSource, string dirPathTarget, string dirPathTemp, Action<string> SetInfo, Action<int> SetConAll, Action<int> SetConWait, Action<int> SetConComplete){SetInfo("开始获取目标文件夹文件列表:" + dirPathTarget);var ccc = new DirectoryInfo(dirPathTarget);var targetFileAll = new DirectoryInfo(dirPathTarget).GetFiles();targetFileNameList = targetFileAll.Select(t => t.Name).ToList();SetInfo("获取到文件数量:" + targetFileNameList.Count);SetInfo("开始获取文件夹文件:" + dirPathSource);var fileArr = new DirectoryInfo(dirPathSource).GetFiles(); SetInfo("获取到文件数量:" + fileArr.Length);Task.Run(() =>{for (int i = 0; i < 100; i++){Application.Current.Dispatcher.Invoke(() =>{SetInfo("AAAAAAAAA" + i);});Thread.Sleep(100);}});}private List<string> targetFileNameList { get; set; }}
}

 

 

 7. 运行

 

 

 

 

 

 

 

 

 

 

end.

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/71548.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

Spring 实现 3 种异步流式接口,干掉接口超时烦恼

大家好,我是小富~ 如何处理比较耗时的接口? 这题我熟,直接上异步接口,使用 Callable、WebAsyncTask 和 DeferredResult、CompletableFuture等均可实现。 但这些方法有局限性,处理结果仅返回单个值。在某些场景下,如果需要接口异步处理的同时,还持续不断地向客户端响应处…

世界空间到观察空间的矩阵

1)世界空间到观察空间的矩阵2)Addressable在不同工程中如何实现打包和加载3)如何设计角色在下蹲时允许跳跃4)如何实时编辑玩家的近裁剪面距离这是第403篇UWA技术知识分享的推送,精选了UWA社区的热门话题,涵盖了UWA问答、社区帖子等技术知识点,助力大家更全面地掌握和学习…

rocketMQ中事务发送消息

rocketMQ中有关事务的发送消息方式,写的一个demo 1、在MyProducer类中的方法,即先定义调用@Component public class MyProducer {@Autowiredprivate RocketMQTemplate template; public void sendTractionMessage(String topic, String msg) throws InterruptedException {St…

为什么线下面试越来越流行了?

不知道大家有没有发现,最近在找工作时,越来越多的公司开始要求必须线下面试了,例如,深信服:例如,华为:还有公司在发布招聘信息时也明确写明了“只能线下面试”:那背后的原因究竟是啥呢? 原因一:作弊成本越来越低 AI 的诞生确实提供了很多便利,但也有人和团队利用 AI…

罗技键鼠在使用Synergy中的灵敏度问题

罗技键鼠在使用Synergy中的灵敏度问题 设备清单mac电脑一台(作为主控端) windows电脑一台(作为被控端) logi master系列键鼠一套遇到的问题 Synergu已经正常启用。mac作为主控设备,且关闭了logi flow情况下,在windows(被控端)使用鼠标明显慢很多,原因是罗技鼠标在mac上…

HDLBits 练习题:8位移位寄存器

HDLBits 练习题:8 位移位寄存器 原题 This exercise is an extension of module_shift. Instead of module ports being only single pins, we now have modules with vectors as ports, to which you will attach wire vectors instead of plain wires. Like everywhere else…

IntelliJ IDEA 2024激活码(亲测有效,仅供学习和交流)

资源是从官网购买,仅供学习和交流 激活码链接地址

任务类型和字段自定义,支撑个性化业务管理

一句话介绍 任务类型和任务字段自定义,面向企业内部不同业务部门,在管理各自任务的时候有不同信息管理差异的场景。企业根据自己的任务管理需求,自定义任务类型,配置不同的任务字段,解决差异化的任务管理场景。 应用场景某互联网企业,企业内部有研发部,有销售部 研发部通…