using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; using TeamAAS_VP.Core; namespace TeamAAS_VP.ValueConverter { public class ImageFileNameFormatConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { if (value == null) return string.Empty; // 创建模板,使用 {变量名:格式} 语法 var template = new FileNameTemplate(value.ToString()); // 注册变量 template.RegisterVariable("ProductSN", () => "SN12345"); template.RegisterVariable("CameraName", () => "MainCamera"); template.RegisterVariable("ShotCount", () => 3); template.RegisterVariable("Result", () => "OK"); template.RegisterVariable("DateTime", () => DateTime.Now); // 生成文件名 string fileName = template.Generate(); return fileName; } catch (Exception) { return value.ToString(); } } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } }