随笔 - 46,  文章 - 0,  评论 - 2,  阅读 - 80889

使用转换器,将字符串值做处理:

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
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
 
namespace Controls.Converters
{
    public class StringSpaceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string str = string.Empty;
            if(!string.IsNullOrWhiteSpace((string)value))
            {
                str = (string)value;
                var a = System.Text.RegularExpressions.Regex.Replace(str, @"(\w{4})", "$1 ").Trim(' ');
                return a;
            }
            return str;
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

 

页面上使用静态资源,引用此转换:

<convert:StringSpaceConverter x:Key="StringSpaceConverter" />

<TextBlock FontSize="48" HorizontalAlignment="Left"  Foreground="{DynamicResource CardFontForBrush}" Text="{Binding DataModel.vip_no,Converter={StaticResource StringSpaceConverter}}" />
 

 

posted @ 2023-09-25 14:56 潇潇烟雨 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 页面中TextBlock控件内容 <TextBlock x:Name="name" HorizontalAlignment="Left" Text="{Binding Name,Converter={StaticResource StringMaxLenConverter},ConverterPar 阅读全文
posted @ 2023-09-19 18:26 潇潇烟雨 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 1、创建一个.xaml文件,页面布局: <UserControl x:Class="Module.ScreentView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schema 阅读全文
posted @ 2023-09-18 09:39 潇潇烟雨 阅读(334) 评论(0) 推荐(0) 编辑
摘要: 封装一个异步方法类: using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Co 阅读全文
posted @ 2023-09-12 17:01 潇潇烟雨 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 在xmal.cs文件中实现,或者重写OnPreviewKeyDown()方法: string codeValue = ""; int InputCount = 0; protected override void OnPreviewKeyDown(KeyEventArgs e) { int keyV 阅读全文
posted @ 2023-09-12 11:58 潇潇烟雨 阅读(589) 评论(0) 推荐(0) 编辑
摘要: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Controls; using System.Windows.Controls.Pri 阅读全文
posted @ 2023-09-11 09:24 潇潇烟雨 阅读(112) 评论(0) 推荐(0) 编辑
摘要: WPF控件帮助类,实现字体自适应,图片上传解码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Wind 阅读全文
posted @ 2023-09-11 09:18 潇潇烟雨 阅读(279) 评论(0) 推荐(0) 编辑
摘要: using Microsoft.Win32; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Controls.Helper { public class 阅读全文
posted @ 2023-09-08 19:47 潇潇烟雨 阅读(107) 评论(0) 推荐(0) 编辑
摘要: using System; using System.IO; using System.Text; namespace Controls.Helper { public class LoggerHelper { private static object o = new object(); priv 阅读全文
posted @ 2023-09-08 19:38 潇潇烟雨 阅读(31) 评论(0) 推荐(0) 编辑
摘要: //默认配置文件 public static string initConfigFilePath = AppDomain.CurrentDomain.BaseDirectory + @"CfgFiles\InitConfig.config"; public static string newExeC 阅读全文
posted @ 2023-09-08 19:34 潇潇烟雨 阅读(175) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 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
点击右上角即可分享
微信分享提示