应用程序路径方式信息WPF(应用程序窗体目录路径名称)「应用程序路径问题」

Xaml<Window x:Class="ApplicationPathInfoWpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ApplicationPathInfoWpf" mc:Ignorable="d" Height="850" Width="900" Name="GetPathWindow" Title="获取应用运行信息"> <Grid> <TextBlock x:Name="TextBlockPath" Margin="20" Width="Auto" Height="830" LineHeight="32" FontSize="14"/> </Grid></Window>Xaml.cspublic MainWindow(){ InitializeComponent(); LoadApplicationDirectory();}private void LoadApplicationDirectory(){ StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("可获得当前执行的exe的文件名"); stringBuilder.AppendLine("Process.GetCurrentProcess().MainModule.FileName"); stringBuilder.AppendLine(Process.GetCurrentProcess().MainModule.FileName); stringBuilder.AppendLine("获取和设置当前目录(即该进程从中启动的目录)的完全限定路径"); stringBuilder.AppendLine("Environment.CurrentDirectory"); stringBuilder.AppendLine(Environment.CurrentDirectory); stringBuilder.AppendLine("获取应用程序的当前工作目录"); stringBuilder.AppendLine("Directory.GetCurrentDirectory()"); stringBuilder.AppendLine(Directory.GetCurrentDirectory()); stringBuilder.AppendLine("获取基目录,它由程序集冲突解决程序用来探测程序集"); stringBuilder.AppendLine("AppDomain.CurrentDomain.BaseDirectory"); stringBuilder.AppendLine(AppDomain.CurrentDomain.BaseDirectory); stringBuilder.AppendLine("获取或设置包含该应用程序的目录的名称"); stringBuilder.AppendLine("AppDomain.CurrentDomain.SetupInformation.ApplicationBase"); stringBuilder.AppendLine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase); stringBuilder.AppendLine("获取应用程序主窗体名称"); stringBuilder.AppendLine("Application.Current.MainWindow.ToString()"); stringBuilder.AppendLine(Application.Current.MainWindow.ToString()); stringBuilder.AppendLine("获取应用程序基目录的名称"); stringBuilder.AppendLine("System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase"); stringBuilder.AppendLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase); stringBuilder.AppendLine("获取当前应用程序集版本号"); System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); stringBuilder.AppendLine("assembly.GetName().Version.ToString()"); stringBuilder.AppendLine(assembly.GetName().Version.ToString()); System.Reflection.AssemblyCopyrightAttribute copyright = (System.Reflection.AssemblyCopyrightAttribute) System.Reflection.AssemblyCopyrightAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(System.Reflection.AssemblyCopyrightAttribute)); System.Reflection.AssemblyDescriptionAttribute description = (System.Reflection.AssemblyDescriptionAttribute) System.Reflection.AssemblyDescriptionAttribute.GetCustomAttribute(System.Reflection.Assembly.GetExecutingAssembly(), typeof(System.Reflection.AssemblyDescriptionAttribute)); stringBuilder.AppendLine("获取当前应用程序集说明"); stringBuilder.AppendLine("description.Description"); stringBuilder.AppendLine(description == null ? "" : description.Description); stringBuilder.AppendLine("获取当前应用程序集版本"); stringBuilder.AppendLine("copyright.Copyright"); stringBuilder.AppendLine(copyright == null ? "" : copyright.Copyright); TextBlockPath.Text = stringBuilder.ToString();}查找窗体是否打开 /// <summary> /// 查找窗体是否打开 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T FindWindow<T>() where T : Window { return Application.Current.Windows.OfType<T>().SingleOrDefault(); } //判断逻辑 MainWindow mainWindow = FindWindow<MainWindow>(); if (mainWindow == null) { MessageBox.Show("没有打开窗体"); } else { MessageBox.Show("已打开窗体"); }静态图片
应用程序路径方式信息WPF(应用程序窗体目录路径名称)
(图片来源网络,侵删)

联系我们

在线咨询:点击这里给我发消息