2025年5月28日

.net8 项目指定包还原位置和读取位置以便备份依赖项

摘要: 1.在 Project 根目录新建 NuGet.Config,设置依赖下载位置 <?xml version="1.0" encoding="utf-8"?> <configuration> <config> <add key="globalPackagesFolder" value=".\packa 阅读全文

posted @ 2025-05-28 17:26 空明流光 阅读(12) 评论(0) 推荐(0)

2025年5月22日

wpf 访问内置资源

摘要: var elementFontFamily = new System.Windows.Media.FontFamily(new Uri("pack://application:,,,/MyMediaPlayer;component/Fonts/"), "./#element"); MyMediaPl 阅读全文

posted @ 2025-05-22 12:19 空明流光 阅读(7) 评论(0) 推荐(0)

2025年5月21日

C# UTF-8 各种编码比较

摘要: void Main() { var code1 = new UTF8Encoding(true); var code2 = new UTF8Encoding(false); var code3 = new UTF8Encoding(); var code4 = Encoding.UTF8; var 阅读全文

posted @ 2025-05-21 10:26 空明流光 阅读(8) 评论(0) 推荐(0)

2025年5月16日

vs2022 wpf 无法识别 xaml 中定义的控件名称

摘要: 在 .csproj 如果没有如下节点,则定义一个,编译如果说重复,删除或注释即可恢复正常: <ItemGroup> <Compile Include="MainWindow.xaml.cs"> <DependentUpon>MainWindow.xaml</DependentUpon> </Comp 阅读全文

posted @ 2025-05-16 11:53 空明流光 阅读(15) 评论(0) 推荐(0)

2025年4月28日

wpf 使用 cursor 命令

摘要: 在 Cursor 中创建 WPF 项目需要依赖 ‌.NET SDK‌ 和 ‌C# 扩展‌,以下是具体步骤: ‌1. 前置条件‌ ‌安装 .NET SDK‌(Windows 必备)从 微软官网 下载并安装最新版 ‌.NET 6/7/8 SDK‌(WPF 项目需要 .NET Desktop Runtim 阅读全文

posted @ 2025-04-28 19:16 空明流光 阅读(95) 评论(0) 推荐(0)

2025年4月25日

wpf datagrid 过滤数据两种方式?

摘要: 1. 使用 visible 属性动态绑定 优点:实时性很高 缺点:耗资源 public class TaskVisibilityConverter : IMultiValueConverter { public object Convert(object[] values, Type targetT 阅读全文

posted @ 2025-04-25 16:11 空明流光 阅读(16) 评论(0) 推荐(0)

2025年4月20日

设置电脑 IPv6 优先

摘要: 管理员身份启动 cmd.exe,执行以下命令: netsh interface ipv6 set prefixpolicy ::/0 100 1 # 提升IPv6优先级到 100(最大为100) netsh interface ipv6 set prefixpolicy ::ffff:0:0/96 阅读全文

posted @ 2025-04-20 12:50 空明流光 阅读(221) 评论(0) 推荐(0)

2025年3月27日

WPF 自定义控件之 Button

摘要: XAML: <Button x:Class="MyMediaPlayer.UserControls.RoundedImageButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http: 阅读全文

posted @ 2025-03-27 11:43 空明流光 阅读(14) 评论(0) 推荐(0)

2025年3月26日

wpf 中 自定义模板关键属性 ContentPresenter 和 ItemsHost

摘要: 在 WPF 中,<ContentPresenter /> 是一个非常重要的元素,通常用于自定义控件模板中。它的主要作用是表示控件的内容,并且允许你将内容(例如文本、图像或其他控件)插入到控件的特定位置。 1‌. 自定义 Button 模板‌: <ControlTemplate TargetType= 阅读全文

posted @ 2025-03-26 11:44 空明流光 阅读(39) 评论(0) 推荐(0)

2025年3月25日

wpf 加载自定义字体

摘要: var families = Fonts.GetFontFamilies(new Uri("pack://application:,,,/MyMediaPlayer;component/Fonts/")); foreach (var family in families) { Console.Wri 阅读全文

posted @ 2025-03-25 15:17 空明流光 阅读(29) 评论(0) 推荐(0)

2025年3月24日

mvvm 事件绑定

摘要: Xaml: <!-- MainWindow.xaml --> <Window x:Class="WpfApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://s 阅读全文

posted @ 2025-03-24 12:27 空明流光 阅读(14) 评论(0) 推荐(0)

2025年3月23日

wpf webview2 大坑

摘要: 最大的坑:没有任何控件可以显示在 WebView2 控件之上,就算显示在那儿了,事件也可以响应,但绝对看不见,WebView2 控件都给你刷新成网页视觉内容了。 官方建议使用 wpf WebView2CompositionControl 替代,确实解决了上述 bug。没深入研究,但一启动网页右键上下 阅读全文

posted @ 2025-03-23 21:27 空明流光 阅读(92) 评论(0) 推荐(0)

Task.WhenAny 的陷阱

摘要: 最近做的一个下载程序经常会陷入死循环,一直下载,未报异常,但就是下载的文件不存在。 public async Task<bool> DownloadFileTimeout(string fileUrl, string savePath) { var timeoutTask = Task.Delay( 阅读全文

posted @ 2025-03-23 09:12 空明流光 阅读(12) 评论(0) 推荐(0)

2025年3月20日

WPF 绑定资源文件出错 无法将 Properties.Resources StaticExtension 值解析为枚举、静态字段或静态属性

摘要: 解决方法:选中项目中资源文件 Resources.resx,在属性窗口中将 ResXFileCodeGenerator 改为 PublicResXFileCodeGenerator 有点扯淡呀,VS问题,不同版本创建的这个选项不一样 阅读全文

posted @ 2025-03-20 20:30 空明流光 阅读(15) 评论(0) 推荐(0)

2025年3月18日

如何正确初始化 Webview2

摘要: var webView = new Microsoft.Web.WebView2.Wpf.WebView2(); gridMain.Children.Add(webView); await webView.EnsureCoreWebView2Async(null); webView.Source = 阅读全文

posted @ 2025-03-18 17:38 空明流光 阅读(69) 评论(0) 推荐(0)

2025年3月6日

c# OllamaSharp DeepSeek 有上下文可连续对话

摘要: 使用 ollama 安装完 deepseek 后, nuget 安装 OllamaSharp ,使用如下代码可实现完整对话,我使用的模型是 DeepSeek-Coder-V2-Lite,以下是核心代码: public class DeepSeekChat { IChatClient chatClie 阅读全文

posted @ 2025-03-06 09:49 空明流光 阅读(189) 评论(0) 推荐(0)

2025年2月4日

动态改变 log4net 日志位置

摘要: private static void changeLogFileLocation() { var logPath = ProfileHelper.GetLogPath(); // 获取当前的日志记录器 var hierarchy = (Hierarchy)LogManager.GetReposit 阅读全文

posted @ 2025-02-04 12:23 空明流光 阅读(41) 评论(0) 推荐(0)

winform 无窗体保持消息循环

摘要: static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetC 阅读全文

posted @ 2025-02-04 11:44 空明流光 阅读(11) 评论(0) 推荐(0)

2025年1月16日

Newtonsoft.Json 序列化时按格式自动换行

摘要: File.WriteAllText(wordCouplePinyinFilepath, JsonConvert.SerializeObject(dictWordCouples, new JsonSerializerSettings { Formatting = Formatting.Indented 阅读全文

posted @ 2025-01-16 22:48 空明流光 阅读(40) 评论(0) 推荐(0)

2025年1月13日

c# 打印各种符号和所有汉字一区的汉字

摘要: void Main() { var items = new List<string> {@"\uFF00-\uFFEF",@"\u2150-\u218F",@"\u2200-\u22FF",@"\u2460-\u24FF",@"\u2600-\u26FF",@"\u3000-\u303F", @"\ 阅读全文

posted @ 2025-01-13 17:52 空明流光 阅读(38) 评论(0) 推荐(0)

2024年12月29日

汉字及扩展汉字编码范围

摘要: 基本汉字([\u4e00-\u9fa5]): 这个范围包含了常见的汉字,是最基本的汉字字符集,常用于日常书写和印刷。 包括了现代汉语常用的绝大多数字符,包含了常见的词汇和地名等。 扩展汉字 A 区([\u3400-\u4DBF]): 这个区域包含了一些较为少见的汉字,主要是古文、方言字、或特殊符号等 阅读全文

posted @ 2024-12-29 15:51 空明流光 阅读(595) 评论(0) 推荐(0)

2024年12月21日

c# 通过正则对多个匹配结果进行个性化替换

摘要: void Main() { string input = "abcdef ghi jklmnop qrst uvwxyz"; // 正则表达式匹配所有字母(包括大小写字母) string pattern = @"[a-zA-Z]+"; // 使用 MatchEvaluator 在替换时处理每个匹配项 阅读全文

posted @ 2024-12-21 16:47 空明流光 阅读(56) 评论(0) 推荐(0)

2024年12月14日

wpf textbox 实现水印

摘要: <TextBox Width="200" VerticalContentAlignment="Center" Background="Transparent" Tag="Enter here..."> <TextBox.Style> <Style TargetType="{x:Type TextBo 阅读全文

posted @ 2024-12-14 12:07 空明流光 阅读(110) 评论(0) 推荐(0)

2024年11月5日

js 阻止后退

摘要: 第一步: // 禁止后退功能 if (typeof history.pushState == 'function') { history.pushState(null, null, location.href); history.back(); history.forward(); } 第二步: / 阅读全文

posted @ 2024-11-05 12:41 空明流光 阅读(141) 评论(0) 推荐(0)

2024年10月29日

c# winform 强制开启 dpi 感知

摘要: [DllImport("user32.dll")] private static extern bool SetProcessDPIAware(); 阅读全文

posted @ 2024-10-29 15:50 空明流光 阅读(37) 评论(0) 推荐(0)

2024年10月26日

.net8 winform 发布

摘要: 或者执行命令:dotnet publish -p:PublishSingleFile=true 阅读全文

posted @ 2024-10-26 19:11 空明流光 阅读(84) 评论(0) 推荐(0)

2024年10月22日

c# winform 将 Form 添加到控件中

摘要: var form1 = new Form() { TopLevel = false, Visible = true }; tabs.TabPages[0].Controls.Add(form1); form1.BringToFront(); 阅读全文

posted @ 2024-10-22 09:28 空明流光 阅读(56) 评论(0) 推荐(0)

2024年10月20日

js 中主窗口与 iframe 通信

摘要: if (window.top window.self) { window.addEventListener('message', function (event) { alert(event.data) }); } else { window.parent.postMessage("Hello fr 阅读全文

posted @ 2024-10-20 14:44 空明流光 阅读(49) 评论(0) 推荐(0)

c# 动态增删 url 中的 query string 查询参数

摘要: void Main() { var url = "http://www.demo.com/demo.html?a=1&b=2"; var uri = new Uri(url); var parameters = HttpUtility.ParseQueryString(uri.Query); par 阅读全文

posted @ 2024-10-20 12:10 空明流光 阅读(28) 评论(0) 推荐(0)

2024年10月19日

WebView2 拦截查看所有的请求

摘要: 有两种方式: 1. 使用 devtool protocol: // 启用网络监控 await webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Network.enable", "{}"); //注册 Network.requestWillB 阅读全文

posted @ 2024-10-19 10:32 空明流光 阅读(845) 评论(1) 推荐(1)

2024年10月18日

c# winform datagridview 显示行号

摘要: 长时间不写,就忘了,备忘一下 dataGridView1.RowHeadersVisible = true; dataGridView1.RowHeadersWidth = 150; dataGridView1.RowStateChanged += (s, args) => { args.Row.H 阅读全文

posted @ 2024-10-18 20:19 空明流光 阅读(326) 评论(0) 推荐(0)

2024年10月16日

c# winform 显示一个 tip

摘要: public void showTip(string text, int duration = 2000) { var form = new Form { Size = new Size(1, 1), StartPosition = FormStartPosition.CenterScreen }; 阅读全文

posted @ 2024-10-16 23:30 空明流光 阅读(56) 评论(0) 推荐(0)

c# .net8 winform 嵌入 wpf 控件

摘要: .net framework 例子很多,但 .netcore 的很难找,经过和 gpt 很长时间的沟通,完成了。 关键点是 vs2022 似乎还不支持设计时的 ElementHost,所以必须通过代码初始化。 1. 新建一个 wpf 控件库 2. 创建一个导圆角的 TextBox,控件名为 User 阅读全文

posted @ 2024-10-16 19:12 空明流光 阅读(519) 评论(0) 推荐(0)

2024年10月14日

C# Mutex 在异步方法中线程同步失效

摘要: Mutex 在异步方法中线程同步失效: private readonly Mutex mutexInitialize = new Mutex(); public async Task<bool> Initialize() { mutexInitialize.WaitOne(); try { ... 阅读全文

posted @ 2024-10-14 23:38 空明流光 阅读(77) 评论(0) 推荐(0)

C# WinForm 菜单项的大小、高宽的手动控制

摘要: 转载:C# WinForm 菜单项的大小、高宽的手动控制 - 清潭荷韵 - 博客园 (cnblogs.com) 感觉有用,怕搜不到,于是转一下 控制菜单项的第一级的下级菜单项的大小: 直接通过(ContextMenuStrip对象).AutoSize = false、(ContextMenuStri 阅读全文

posted @ 2024-10-14 18:47 空明流光 阅读(129) 评论(0) 推荐(0)

webview2 获取页面截图

摘要: var ms = new MemoryStream(); await Browser.CoreWebView2.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, ms); { var bytes = ms.ToArray() 阅读全文

posted @ 2024-10-14 15:09 空明流光 阅读(341) 评论(0) 推荐(0)

2024年10月12日

c# winform 高 dpi 自适应开发步骤

摘要: 1. 在不启用 dpi aware 模式下开发 2. 启动 dpi aware 3. 对有问题的控件使用 DpiHelper 对定位和大小或者图像进行转换 参见 解决 DPI 问题 - Visual Studio (Windows) | Microsoft Learn 部分官方示例: 若要从将在 V 阅读全文

posted @ 2024-10-12 13:52 空明流光 阅读(276) 评论(0) 推荐(0)

2024年10月11日

c# 注册协议处理程序

摘要: static void registerAsHttpHandler() { // Register as the default handler for the http: protocol. const string protocolValue = "HTTP:Hypertext Transfer 阅读全文

posted @ 2024-10-11 22:07 空明流光 阅读(13) 评论(0) 推荐(0)

c# 捕获系统快捷键

摘要: private void GlobalKeyCapture_KeyDown(object sender, KeyEventArgs e) { //判断当前进程是否是活动进程,以决定是否响应 var currentProcess = getActiveProcess(); if (currentPro 阅读全文

posted @ 2024-10-11 11:57 空明流光 阅读(29) 评论(0) 推荐(0)

2024年9月29日

c# webclient 使用默认代理的代码

摘要: void Main() { using (WebClient client = new WebClient()) { // 使用默认代理 client.Proxy = WebRequest.GetSystemWebProxy(); // 你可以选择是否设置凭据 client.Credentials 阅读全文

posted @ 2024-09-29 21:15 空明流光 阅读(26) 评论(0) 推荐(0)

导航

< 2025年7月 >
29 30 1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31 1 2
3 4 5 6 7 8 9
点击右上角即可分享
微信分享提示