diff --git a/IconResources/IconResources.csproj b/IconResources/IconResources.csproj index 2c5fda1..74d4596 100644 --- a/IconResources/IconResources.csproj +++ b/IconResources/IconResources.csproj @@ -9,8 +9,9 @@ Properties IconResources IconResources - v4.5 + v4.8 512 + true diff --git a/IconResources/Images/Icons.cs b/IconResources/Images/Icons.cs index 4a87717..921ff84 100644 --- a/IconResources/Images/Icons.cs +++ b/IconResources/Images/Icons.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using System.Windows; namespace IconResources.Images diff --git a/SvgConverter/ConverterLogic.cs b/SvgConverter/ConverterLogic.cs index d8e3ee1..e74096f 100644 --- a/SvgConverter/ConverterLogic.cs +++ b/SvgConverter/ConverterLogic.cs @@ -50,9 +50,11 @@ public static ConvertedSvgData ConvertSvg(string filepath, ResultMode resultMode //var obj = ConvertSvgToObject(filepath, resultMode, null, out name) as DependencyObject; //var xaml = SvgObjectToXaml(obj, false, name); //var svg = File.ReadAllText(filepath); - - return new ConvertedSvgData { Filepath = filepath - //, ConvertedObj = obj, Svg = svg, Xaml = xaml + + return new ConvertedSvgData + { + Filepath = filepath + //, ConvertedObj = obj, Svg = svg, Xaml = xaml }; } @@ -163,21 +165,21 @@ private static void ReplaceBrushesInDrawingGroupsOld(XElement rootElement, ResKe .Distinct(StringComparer.InvariantCultureIgnoreCase) //same Color only once .Select((s, i) => new { - ResKey1 = BuildColorName(i+1, resKeyInfo), - ResKey2 = BuildColorBrushName(i + 1, resKeyInfo), + ResKey1 = BuildColorName(i + 1, resKeyInfo), + ResKey2 = BuildColorBrushName(i + 1, resKeyInfo), Color = s }) //add numbers .ToList(); //building global Elements like: rootElement.AddFirst(allBrushes - .Select(brush => new XElement(NsDef + "SolidColorBrush", + .Select(brush => new XElement(NsDef + "SolidColorBrush", new XAttribute(Nsx + "Key", brush.ResKey2), new XAttribute("Color", $"{{DynamicResource {brush.ResKey1}}}")))); //building global Elements like: #FF000000 rootElement.AddFirst(allBrushes - .Select(brush => new XElement(NsDef + "Color", + .Select(brush => new XElement(NsDef + "Color", new XAttribute(Nsx + "Key", brush.ResKey1), brush.Color))); @@ -191,24 +193,24 @@ private static void ReplaceBrushesInDrawingGroupsOld(XElement rootElement, ResKe var keyDg = node.Attribute(Nsx + "Key").Value; var elemName = GetElemNameFromResKey(keyDg, resKeyInfo); var elemBaseName = elemName.Replace("DrawingGroup", ""); - + var brushAttributes = CollectBrushAttributesWithColor(node).ToList(); - + foreach (var brushAttribute in brushAttributes) { var color = brushAttribute.Value; string resKeyColor; if (colorKeys.TryGetValue(color, out resKeyColor)) { //global color found - + //build resourcename var nameBrush = brushAttributes.Count > 1 ? $"{elemBaseName}Color{brushAttributes.IndexOf(brushAttribute) + 1}Brush" : $"{elemBaseName}ColorBrush"; //dont add number if only one color var resKeyBrush = BuildResKey(nameBrush, resKeyInfo); - node.AddBeforeSelf(new XElement(NsDef + "SolidColorBrush", - new XAttribute(Nsx + "Key", resKeyBrush), - new XAttribute("Color", $"{{Binding Color, Source={BuildResKeyReference(resKeyColor, false)}}}") )); + node.AddBeforeSelf(new XElement(NsDef + "SolidColorBrush", + new XAttribute(Nsx + "Key", resKeyBrush), + new XAttribute("Color", $"{{Binding Color, Source={BuildResKeyReference(resKeyColor, false)}}}"))); //set brush value as Reference // brushAttribute.Value = BuildResKeyReference(resKeyBrush, true); @@ -224,7 +226,7 @@ private static void ReplaceBrushesInDrawingGroups(XElement rootElement, ResKeyIn foreach (var node in drawingGroups) { var brushAttributes = CollectBrushAttributesWithColor(node).ToList(); - + foreach (var brushAttribute in brushAttributes) { var color = brushAttribute.Value; @@ -386,8 +388,8 @@ private static bool IsSvgz(string filepath) private static void FixIds(XElement root) { var idAttributesStartingWithDigit = root.DescendantsAndSelf() - .SelectMany(d=>d.Attributes()) - .Where(a=>string.Equals(a.Name.LocalName, "Id", StringComparison.InvariantCultureIgnoreCase)); + .SelectMany(d => d.Attributes()) + .Where(a => string.Equals(a.Name.LocalName, "Id", StringComparison.InvariantCultureIgnoreCase)); foreach (var attr in idAttributesStartingWithDigit) { if (char.IsDigit(attr.Value.FirstOrDefault())) @@ -407,7 +409,7 @@ internal static DrawingImage DrawingToImage(Drawing drawing) internal static string WpfObjToXaml(object wpfObject, bool includeRuntime) { - XmlXamlWriter writer = new XmlXamlWriter(new WpfDrawingSettings { IncludeRuntime = includeRuntime}); + XmlXamlWriter writer = new XmlXamlWriter(new WpfDrawingSettings { IncludeRuntime = includeRuntime }); var xaml = writer.Save(wpfObject); return xaml; } @@ -545,7 +547,7 @@ private static void ExtractGeometries(XElement drawingGroupElement, ResKeyInfo r : (int?)null; var localName = BuildGeometryName(name, no, resKeyInfo); //Add this: F1 M512,512z M0,0z M409.338,216.254C398.922,351.523z - drawingGroupElement.AddBeforeSelf(new XElement(NsDef+"Geometry", + drawingGroupElement.AddBeforeSelf(new XElement(NsDef + "Geometry", new XAttribute(Nsx + "Key", localName), geo.Value)); geo.Value = BuildResKeyReference(localName, false); @@ -575,12 +577,12 @@ public static void RemoveObjectNames(DrawingGroup drawingGroup) internal static string BuildDrawingGroupName(string elementName, ResKeyInfo resKeyInfo) { - var rawName = elementName + "DrawingGroup"; + var rawName = ValidateName(elementName).Trim('_') + "_DrawingGroup"; return BuildResKey(rawName, resKeyInfo); } internal static string BuildDrawingImageName(string elementName, ResKeyInfo resKeyInfo) { - var rawName = elementName + "DrawingImage"; + var rawName = ValidateName(elementName).Trim('_') + "_DrawingImage"; return BuildResKey(rawName, resKeyInfo); } diff --git a/SvgConverter/SvgConverter.csproj b/SvgConverter/SvgConverter.csproj index efdaa43..fa42ee0 100644 --- a/SvgConverter/SvgConverter.csproj +++ b/SvgConverter/SvgConverter.csproj @@ -9,7 +9,7 @@ Properties SvgConverter SvgConverter - v4.6.2 + v4.8 512 diff --git a/SvgConverter/app.config b/SvgConverter/app.config index 8e06ccc..d5177f3 100644 --- a/SvgConverter/app.config +++ b/SvgConverter/app.config @@ -20,4 +20,4 @@ - + diff --git a/SvgConverterTest/SvgConverterTest.csproj b/SvgConverterTest/SvgConverterTest.csproj index 9b3f189..6b9fba8 100644 --- a/SvgConverterTest/SvgConverterTest.csproj +++ b/SvgConverterTest/SvgConverterTest.csproj @@ -8,7 +8,7 @@ Properties SvgConverterTest SvgConverterTest - v4.6.2 + v4.8 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 diff --git a/SvgConverterTest/app.config b/SvgConverterTest/app.config index 8e06ccc..d5177f3 100644 --- a/SvgConverterTest/app.config +++ b/SvgConverterTest/app.config @@ -20,4 +20,4 @@ - + diff --git a/SvgToXaml/DetailWindow.xaml b/SvgToXaml/DetailWindow.xaml index 77f583e..bb65197 100644 --- a/SvgToXaml/DetailWindow.xaml +++ b/SvgToXaml/DetailWindow.xaml @@ -1,56 +1,91 @@ - + - - + + - - + + - + - + - - + + - - + + - + - - + + - - - - - + + + + + - + - - + + - - + + @@ -58,20 +93,29 @@ - - + + - - - - + + - + diff --git a/SvgToXaml/DetailWindow.xaml.cs b/SvgToXaml/DetailWindow.xaml.cs index 31729c7..03b1503 100644 --- a/SvgToXaml/DetailWindow.xaml.cs +++ b/SvgToXaml/DetailWindow.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Linq; using System.Windows; using System.Windows.Input; @@ -18,7 +19,14 @@ public DetailWindow() private void CopyToClipboardClick(object sender, RoutedEventArgs e) { - Clipboard.SetText(XmlViewer.Text); + try + { + Clipboard.SetText(XmlViewer.Text); + } + catch (Exception ex) + { + Trace.TraceError(ex.Message); + } } private void ToggleStretchClicked(object sender, MouseButtonEventArgs e) diff --git a/SvgToXaml/Explorer/FolderTree.xaml.cs b/SvgToXaml/Explorer/FolderTree.xaml.cs index 74497b4..2f62e04 100644 --- a/SvgToXaml/Explorer/FolderTree.xaml.cs +++ b/SvgToXaml/Explorer/FolderTree.xaml.cs @@ -15,19 +15,19 @@ namespace SvgToXaml.Explorer public partial class FolderTree { public static readonly DependencyProperty CurrentFolderProperty = DependencyProperty.Register( - "CurrentFolder", typeof (string), typeof (FolderTree), new PropertyMetadata(default(string), CurrentFolderChanged)); + "CurrentFolder", typeof(string), typeof(FolderTree), new PropertyMetadata(default(string), CurrentFolderChanged)); private static void CurrentFolderChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { FolderTree folderTree = (FolderTree)dependencyObject; - var item = folderTree.FindItem(folderTree.FoldersTree, (string)dependencyPropertyChangedEventArgs.NewValue); - if (item!=null) + var item = folderTree.FindItem(folderTree.FoldersTree, (string)dependencyPropertyChangedEventArgs.NewValue); + if (item != null) folderTree.SelectItem(item); } public string CurrentFolder { - get { return (string) GetValue(CurrentFolderProperty); } + get { return (string)GetValue(CurrentFolderProperty); } set { SetValue(CurrentFolderProperty, value); } } private readonly object _dummyNode = null; @@ -40,11 +40,11 @@ public FolderTree() } public static readonly DependencyProperty ContextMenuCommandsProperty = DependencyProperty.Register( - "ContextMenuCommands", typeof (ObservableCollection>), typeof (FolderTree), new PropertyMetadata(default(ObservableCollection>))); + "ContextMenuCommands", typeof(ObservableCollection>), typeof(FolderTree), new PropertyMetadata(default(ObservableCollection>))); public ObservableCollection> ContextMenuCommands { - get { return (ObservableCollection>) GetValue(ContextMenuCommandsProperty); } + get { return (ObservableCollection>)GetValue(ContextMenuCommandsProperty); } set { SetValue(ContextMenuCommandsProperty, value); } } @@ -56,11 +56,17 @@ private void FoldersTreeOnSelectedItemChanged(object sender, RoutedPropertyChang private void FillRootLevel() { - foreach (var drive in Directory.GetLogicalDrives()) + string[] nodes = [Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + , Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + , .. Directory.GetLogicalDrives()]; + + foreach (var drive in nodes) { - var item = new TreeViewItem(); - item.Header = drive; - item.Tag = drive; + var item = new TreeViewItem + { + Header = drive, + Tag = drive + }; item.Items.Add(_dummyNode); item.Expanded += folder_Expanded; @@ -74,14 +80,14 @@ private void FillRootLevel() private void folder_Expanded(object sender, RoutedEventArgs e) { - var item = (TreeViewItem) sender; + var item = (TreeViewItem)sender; if (item.Items.Count == 1 && item.Items[0] == _dummyNode) { item.Items.Clear(); try { if (item.Tag != null) - foreach (var dir in Directory.GetDirectories((string) item.Tag)) + foreach (var dir in Directory.GetDirectories((string)item.Tag)) { var subitem = new TreeViewItem(); subitem.Header = new DirectoryInfo(dir).Name; diff --git a/SvgToXaml/MainWindow.xaml b/SvgToXaml/MainWindow.xaml index 4bf1350..2be1182 100644 --- a/SvgToXaml/MainWindow.xaml +++ b/SvgToXaml/MainWindow.xaml @@ -1,18 +1,24 @@  + mc:Ignorable="d"> + @@ -23,54 +29,101 @@ - - - + + + - - + + - - - - + + + - - + + - - + + - - + + - + SelectionMode="Single"> - - - - + + - - - + + + - + - + - + - + + + - + @@ -106,11 +163,29 @@ - - + + + + + + + + + - + \ No newline at end of file diff --git a/SvgToXaml/MainWindow.xaml.cs b/SvgToXaml/MainWindow.xaml.cs index f179f66..3d8a591 100644 --- a/SvgToXaml/MainWindow.xaml.cs +++ b/SvgToXaml/MainWindow.xaml.cs @@ -1,13 +1,16 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.IO; using System.Windows; +using System.Windows.Data; +using System.Windows.Media; using SvgToXaml.Properties; using SvgToXaml.ViewModels; namespace SvgToXaml { - //todo: github oder codeplex anlegen - //todo: Fehlerbehandlung beim Laden + //todo: github oder codeplex anlegen + //todo: Fehlerbehandlung beim Laden /// /// Interaction logic for MainWindow.xaml @@ -17,15 +20,20 @@ public partial class MainWindow public MainWindow() { InitializeComponent(); - DataContext = new SvgImagesViewModel(); - ((SvgImagesViewModel) DataContext).CurrentDir = Settings.Default.LastDir; + var vm = new SvgImagesViewModel(); + + DataContext = vm; + vm.CurrentDir = Settings.Default.LastDir; } - + private readonly BrushConverter brushConverter = new(); + private string filterText = ""; + protected override void OnClosing(CancelEventArgs e) { //Save current Dir for next Start - Settings.Default.LastDir = ((SvgImagesViewModel) DataContext).CurrentDir; + var vm = (SvgImagesViewModel)DataContext; + Settings.Default.LastDir = vm.CurrentDir; Settings.Default.Save(); base.OnClosing(e); @@ -41,7 +49,7 @@ private void MainWindow_OnDrop(object sender, DragEventArgs e) { if (Directory.Exists(path)) { - ((SvgImagesViewModel) DataContext).CurrentDir = path; + ((SvgImagesViewModel)DataContext).CurrentDir = path; } else { @@ -53,7 +61,24 @@ private void MainWindow_OnDrop(object sender, DragEventArgs e) } } } - } - -} + private void filterTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) + { + filterText = filterTextBox.Text?.Trim(); + var cvs = (CollectionViewSource)this.FindResource("images_collection"); + cvs.View?.Refresh(); + } + + private void CollectionViewSource_Filter(object sender, System.Windows.Data.FilterEventArgs e) + { + if (e.Item is not ImageBaseViewModel img) return; + + string txt = filterText; + if (String.IsNullOrEmpty(txt)) e.Accepted = true; + else + { + e.Accepted = img.Filename.IndexOf(txt, StringComparison.OrdinalIgnoreCase) > -1; + } + } + } +} \ No newline at end of file diff --git a/SvgToXaml/Properties/Resources.Designer.cs b/SvgToXaml/Properties/Resources.Designer.cs index dd95bb1..ffa8dbd 100644 --- a/SvgToXaml/Properties/Resources.Designer.cs +++ b/SvgToXaml/Properties/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -13,13 +13,13 @@ namespace SvgToXaml.Properties { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -33,7 +33,7 @@ internal Resources() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/SvgToXaml/Properties/Settings.Designer.cs b/SvgToXaml/Properties/Settings.Designer.cs index 6c82e80..10f1180 100644 --- a/SvgToXaml/Properties/Settings.Designer.cs +++ b/SvgToXaml/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace SvgToXaml.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -34,5 +34,17 @@ public string LastDir { this["LastDir"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("AliceBlue")] + public string LastBackgroundBrush { + get { + return ((string)(this["LastBackgroundBrush"])); + } + set { + this["LastBackgroundBrush"] = value; + } + } } } diff --git a/SvgToXaml/Properties/Settings.settings b/SvgToXaml/Properties/Settings.settings index 74d6d7e..1fde58e 100644 --- a/SvgToXaml/Properties/Settings.settings +++ b/SvgToXaml/Properties/Settings.settings @@ -5,5 +5,8 @@ + + AliceBlue + \ No newline at end of file diff --git a/SvgToXaml/SvgToXaml.csproj b/SvgToXaml/SvgToXaml.csproj index 05dd40c..0a59dd1 100644 --- a/SvgToXaml/SvgToXaml.csproj +++ b/SvgToXaml/SvgToXaml.csproj @@ -9,7 +9,8 @@ Properties SvgToXaml SvgToXaml - v4.6.2 + v4.8 + preview 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -21,6 +22,7 @@ full false bin\Debug\ + preview DEBUG;TRACE prompt 4 @@ -33,6 +35,7 @@ true bin\Release\ TRACE + preview prompt 4 false diff --git a/SvgToXaml/ViewModels/ImageBaseViewModel.cs b/SvgToXaml/ViewModels/ImageBaseViewModel.cs index 00882f1..bc43f80 100644 --- a/SvgToXaml/ViewModels/ImageBaseViewModel.cs +++ b/SvgToXaml/ViewModels/ImageBaseViewModel.cs @@ -1,7 +1,10 @@ +using System; using System.Diagnostics; using System.IO; +using System.Windows; using System.Windows.Input; using System.Windows.Media; +using SvgConverter; using SvgToXaml.Command; namespace SvgToXaml.ViewModels @@ -13,13 +16,17 @@ protected ImageBaseViewModel(string filepath) Filepath = filepath; OpenDetailCommand = new DelegateCommand(OpenDetailExecute); OpenFileCommand = new DelegateCommand(OpenFileExecute); + OpenFileLocationCommand = new DelegateCommand(OpenFileLocationExecute); } public string Filepath { get; } public string Filename => Path.GetFileName(Filepath); public ImageSource PreviewSource => GetImageSource(); + public ICommand OpenDetailCommand { get; set; } public ICommand OpenFileCommand { get; set; } + public ICommand OpenFileLocationCommand { get; set; } + protected abstract ImageSource GetImageSource(); public abstract bool HasXaml { get; } public abstract bool HasSvg { get; } @@ -40,6 +47,11 @@ private void OpenFileExecute() Process.Start(Filepath); } + private void OpenFileLocationExecute() + { + Process.Start("explorer.exe", string.Format($"""/select, "{Filepath}" """ )); + } + protected abstract string GetSvgDesignInfo(); } } \ No newline at end of file diff --git a/SvgToXaml/ViewModels/SvgImageViewModel.cs b/SvgToXaml/ViewModels/SvgImageViewModel.cs index cc792fc..fd1ea2a 100644 --- a/SvgToXaml/ViewModels/SvgImageViewModel.cs +++ b/SvgToXaml/ViewModels/SvgImageViewModel.cs @@ -1,7 +1,10 @@ using System; +using System.Diagnostics; using System.Windows; +using System.Windows.Input; using System.Windows.Media; using SvgConverter; +using SvgToXaml.Command; namespace SvgToXaml.ViewModels { @@ -9,9 +12,9 @@ public class SvgImageViewModel : ImageBaseViewModel { private ConvertedSvgData _convertedSvgData; - public SvgImageViewModel(string filepath) : base(filepath) { + CopyAsXamlCommand = new DelegateCommand(CopyAsXamlExecute); } public SvgImageViewModel(ConvertedSvgData convertedSvgData) @@ -39,10 +42,10 @@ protected override string GetSvgDesignInfo() { if (PreviewSource is DrawingImage) { - var di = (DrawingImage) PreviewSource; + var di = (DrawingImage)PreviewSource; if (di.Drawing is DrawingGroup) { - var dg = (DrawingGroup) di.Drawing; + var dg = (DrawingGroup)di.Drawing; var bounds = dg.ClipGeometry?.Bounds ?? dg.Bounds; return $"{bounds.Width:#.##}x{bounds.Height:#.##}"; } @@ -57,7 +60,6 @@ protected override string GetSvgDesignInfo() public string Xaml => SvgData?.Xaml; - public ConvertedSvgData SvgData { get @@ -72,7 +74,7 @@ public ConvertedSvgData SvgData { return null; } - + //verzögertes Laden: ist scheiß lahm //InUi(DispatcherPriority.Loaded, () => //{ @@ -84,5 +86,19 @@ public ConvertedSvgData SvgData return _convertedSvgData; } } + + public ICommand CopyAsXamlCommand { get; } + + private void CopyAsXamlExecute() + { + try + { + Clipboard.SetText(Xaml); + } + catch (Exception ex) + { + Trace.TraceError(ex.Message); + } + } } -} +} \ No newline at end of file diff --git a/SvgToXaml/ViewModels/SvgImagesViewModel.cs b/SvgToXaml/ViewModels/SvgImagesViewModel.cs index 13177b0..884b6ad 100644 --- a/SvgToXaml/ViewModels/SvgImagesViewModel.cs +++ b/SvgToXaml/ViewModels/SvgImagesViewModel.cs @@ -7,9 +7,11 @@ using System.Windows; using System.Windows.Forms; using System.Windows.Input; +using System.Windows.Media; using SvgConverter; using SvgToXaml.Command; using SvgToXaml.Infrastructure; +using SvgToXaml.Properties; using MessageBox = System.Windows.MessageBox; using OpenFileDialog = Microsoft.Win32.OpenFileDialog; @@ -17,22 +19,30 @@ namespace SvgToXaml.ViewModels { public class SvgImagesViewModel : ViewModelBase { - private string _currentDir; - private ObservableCollectionSafe _images; - private ImageBaseViewModel _selectedItem; - public SvgImagesViewModel() { _images = new ObservableCollectionSafe(); + + if (Settings.Default.LastBackgroundBrush is string savedBrush + && BackgroundBrushes.FirstOrDefault(dd=>dd.ToString() == savedBrush) is Brush select) + { + _SelectedBackgroundBrush = select; + } + OpenFileCommand = new DelegateCommand(OpenFileExecute); OpenFolderCommand = new DelegateCommand(OpenFolderExecute); ExportDirCommand = new DelegateCommand(ExportDirExecute); InfoCommand = new DelegateCommand(InfoExecute); - - ContextMenuCommands = new ObservableCollection>(); - ContextMenuCommands.Add(new Tuple("Open Explorer", new DelegateCommand(OpenExplorerExecute))); + ContextMenuCommands = new ObservableCollection> + { + new Tuple("Open Explorer", new DelegateCommand(OpenExplorerExecute)) + }; } + private string _currentDir; + private ObservableCollectionSafe _images; + private ImageBaseViewModel _selectedItem; + private void OpenFolderExecute() { var folderDialog = new FolderBrowserDialog { Description = "Open Folder", SelectedPath = CurrentDir, ShowNewFolderButton = false }; @@ -51,8 +61,8 @@ private void OpenFileExecute() private void ExportDirExecute() { - string outFileName = Path.GetFileNameWithoutExtension(CurrentDir) + ".xaml"; - var saveDlg = new SaveFileDialog {AddExtension = true, DefaultExt = ".xaml", Filter = "Xaml-File|*.xaml", InitialDirectory = CurrentDir, FileName = outFileName}; + string outFileName = Path.GetFileNameWithoutExtension(CurrentDir) + ".xaml"; + var saveDlg = new SaveFileDialog { AddExtension = true, DefaultExt = ".xaml", Filter = "Xaml-File|*.xaml", InitialDirectory = CurrentDir, FileName = outFileName }; if (saveDlg.ShowDialog() == DialogResult.OK) { string namePrefix = null; @@ -72,7 +82,6 @@ private void ExportDirExecute() namePrefix = Microsoft.VisualBasic.Interaction.InputBox("Enter a namePrefix (or leave empty to not use it)", "Name Prefix"); if (string.IsNullOrWhiteSpace(namePrefix)) namePrefix = null; - } outFileName = Path.GetFullPath(saveDlg.FileName); @@ -83,7 +92,6 @@ private void ExportDirExecute() UseComponentResKeys = useComponentResKeys, NameSpace = nameSpace, NameSpaceName = nameSpaceName, - }; File.WriteAllText(outFileName, ConverterLogic.SvgDirToXaml(CurrentDir, resKeyInfo, false)); @@ -99,7 +107,7 @@ private void BuildBatchFile(string outFileName, ResKeyInfo compResKeyInfo) var outputname = Path.GetFileNameWithoutExtension(outFileName); var outputdir = Path.GetDirectoryName(outFileName); var relOutputDir = FileUtils.MakeRelativePath(CurrentDir, PathIs.Folder, outputdir, PathIs.Folder); - var svgToXamlPath =System.Reflection.Assembly.GetEntryAssembly().Location; + var svgToXamlPath = System.Reflection.Assembly.GetEntryAssembly().Location; var relSvgToXamlPath = FileUtils.MakeRelativePath(CurrentDir, PathIs.Folder, svgToXamlPath, PathIs.File); var batchText = $"{relSvgToXamlPath} BuildDict /inputdir \".\" /outputdir \"{relOutputDir}\" /outputname {outputname}"; @@ -152,6 +160,7 @@ private void InfoExecute() { MessageBox.Show("SvgToXaml © 2015 Bernd Klaiber\n\nPowered by\nsharpvectors.codeplex.com (Svg-Support),\nicsharpcode (AvalonEdit)", "Info"); } + private void OpenExplorerExecute(string path) { Process.Start(path); @@ -178,6 +187,22 @@ public string CurrentDir } } + public Brush[] BackgroundBrushes { get; } = new[] { Brushes.WhiteSmoke, Brushes.AliceBlue, Brushes.Pink, }; + + private Brush _SelectedBackgroundBrush = Brushes.WhiteSmoke; + + public Brush SelectedBackgroundBrush + { + get => _SelectedBackgroundBrush; + set + { + if (SetProperty(ref _SelectedBackgroundBrush, value)) + { + Settings.Default.LastBackgroundBrush = value?.ToString(); + } + } + } + public ImageBaseViewModel SelectedItem { get { return _selectedItem; } @@ -205,9 +230,9 @@ private void ReadImagesFromDir(string folder) var graphicFiles = GetFilesMulti(folder, GraphicImageViewModel.SupportedFormats); var graphicImages = graphicFiles.Select(f => new GraphicImageViewModel(f)); - - var allImages = svgImages.Concat(graphicImages).OrderBy(e=>e.Filepath); - + + var allImages = svgImages.Concat(graphicImages).OrderBy(e => e.Filepath); + Images.AddRange(allImages); } @@ -225,4 +250,4 @@ private static string[] GetFilesMulti(string sourceFolder, string filters, Searc } } } -} +} \ No newline at end of file diff --git a/SvgToXaml/app.config b/SvgToXaml/app.config index c18dc03..554d98d 100644 --- a/SvgToXaml/app.config +++ b/SvgToXaml/app.config @@ -5,10 +5,13 @@
- + - + + + + AliceBlue diff --git a/WpfDemoApp/Properties/Resources.Designer.cs b/WpfDemoApp/Properties/Resources.Designer.cs index 8d144a0..31dee34 100644 --- a/WpfDemoApp/Properties/Resources.Designer.cs +++ b/WpfDemoApp/Properties/Resources.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -13,13 +13,13 @@ namespace WpfDemoApp.Properties { /// - /// A strongly-typed resource class, for looking up localized strings, etc. + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -33,7 +33,7 @@ internal Resources() { } /// - /// Returns the cached ResourceManager instance used by this class. + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ internal Resources() { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { diff --git a/WpfDemoApp/Properties/Settings.Designer.cs b/WpfDemoApp/Properties/Settings.Designer.cs index 07af032..83325e1 100644 --- a/WpfDemoApp/Properties/Settings.Designer.cs +++ b/WpfDemoApp/Properties/Settings.Designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ // -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -12,7 +12,7 @@ namespace WpfDemoApp.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/WpfDemoApp/WpfDemoApp.csproj b/WpfDemoApp/WpfDemoApp.csproj index 27ba26c..69bd0cd 100644 --- a/WpfDemoApp/WpfDemoApp.csproj +++ b/WpfDemoApp/WpfDemoApp.csproj @@ -9,7 +9,7 @@ Properties WpfDemoApp WpfDemoApp - v4.5 + v4.8 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 diff --git a/WpfDemoApp/app.config b/WpfDemoApp/app.config index 801c873..2c0f559 100644 --- a/WpfDemoApp/app.config +++ b/WpfDemoApp/app.config @@ -1,3 +1,3 @@ - +