多项功能优化
This commit is contained in:
@@ -17,11 +17,12 @@ public static class WinDialogHelper
|
||||
/// <param name="filterName">过滤器的名称</param>
|
||||
/// <param name="extensions">仅扩展名,*代表所有文件</param>
|
||||
/// <returns></returns>
|
||||
public static string CreateFilter(string filterName, params string[] extensions)
|
||||
public static FileDialog SetFilter(this FileDialog dialog, string filterName, params string[] extensions)
|
||||
{
|
||||
if (extensions[0] == "*")
|
||||
{
|
||||
return "所有文件(*)|*";
|
||||
dialog.Filter = "所有文件(*)|*";
|
||||
//return "所有文件(*)|*";
|
||||
}
|
||||
|
||||
var str = string.Empty;
|
||||
@@ -34,8 +35,9 @@ public static class WinDialogHelper
|
||||
str += ";";
|
||||
}
|
||||
}
|
||||
|
||||
return $"{filterName}({str})|{str}";
|
||||
dialog.Filter = $"{filterName}({str})|{str}";
|
||||
return dialog;
|
||||
//return $"{filterName}({str})|{str}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,9 +52,10 @@ public static class WinDialogHelper
|
||||
new()
|
||||
{
|
||||
CheckFileExists = true,
|
||||
Filter = CreateFilter(title, extensions),
|
||||
|
||||
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
|
||||
};
|
||||
dialog.SetFilter(title, extensions);
|
||||
return dialog.ShowDialog() == true ? dialog.FileName : null;
|
||||
}
|
||||
|
||||
@@ -93,6 +96,7 @@ public static class WinDialogHelper
|
||||
public static void ShowModeless<T>(ObservableObject viewModel)
|
||||
where T : Window, new()
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;
|
||||
var view = SingletonViewHelper<T>.GetInstance(out var isNewCreate);
|
||||
if (isNewCreate)
|
||||
{
|
||||
@@ -100,6 +104,8 @@ public static class WinDialogHelper
|
||||
view.ShowAhead();
|
||||
}
|
||||
view.Activate();
|
||||
AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomainOnAssemblyResolve;
|
||||
|
||||
//AssemblyLoaderHelpers loaderUtil = new(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
|
||||
//loaderUtil.HookAssemblyResolve();
|
||||
//try
|
||||
@@ -121,6 +127,19 @@ public static class WinDialogHelper
|
||||
// loaderUtil.UnhookAssemblyResolve();
|
||||
//}
|
||||
}
|
||||
private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
|
||||
{
|
||||
if (!args.Name.Contains("Xaml.Behaviors"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var assemblyFile = Path.Combine(
|
||||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||
"Microsoft.Xaml.Behaviors.dll"
|
||||
);
|
||||
return File.Exists(assemblyFile) ? Assembly.LoadFrom(assemblyFile) : null;
|
||||
}
|
||||
private static Dictionary<Type, Window> _windows = [];
|
||||
public static void ShowOrActivate<TWindow, TViewModel>(params object[] viewModelParams)
|
||||
where TWindow : Window, new()
|
||||
|
||||
Reference in New Issue
Block a user