在WPF中获取程序运行路径有以下几个方法;

  1.  Environment.CurrentDirectory            :"c:\bin\Debug\"

 2:  AppDomain.CurrentDomain.BaseDirectory

  3. AppDomain.CurrentDomain.SetupInformation.ApplicationBase

  4:Process.GetCurrentProcess().MainModule.FileName

 窗口的ResizeMode属性控制窗口能否变换大小,有CanResize.CanMinimize.CanResizeWithGrip.NoResize 四个选择。

 窗口的WindowStyle属性控制窗口的样式:即None   SingleBorderWindow  ThreeDBorderWindow  ToolWindow

 下面是一个小示例  :程序运行加载界面

 

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Windows.Controls;

namespace xiaohai.WindowExample
{
class Example : Window
{
string s = Environment.CurrentDirectory.ToString();
[STAThread ]
public static void Main()
{
Application app
= new Application();

app.Run(
new Example());


}
public Example()
{

s
= s.Substring(0, s.Length - 9);

Title
= "Text the Window";
ResizeMode
= ResizeMode.NoResize;
WindowStyle
= WindowStyle.None;
Image img
= new Image();
img.Stretch
= Stretch.Fill;
BitmapImage bimg
= new BitmapImage();
bimg.BeginInit();
bimg .UriSource
=new Uri (s+"/Resources/001.jpg",UriKind .Absolute );
bimg .EndInit ();
img.Source
=bimg;
Content
=img ;


}
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Key == Key.Enter)

MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory.ToString()
+"***"+
Environment .CurrentDirectory .ToString ()
+"***"+AppDomain .CurrentDomain .SetupInformation .ApplicationBase .ToString ());

Application.Current.Shutdown();
}
}
}

  运行效果图: