devlights
8/16/2014 - 9:17 AM

アプリケーションのパスを取得 (Application.StartupPath)

アプリケーションのパスを取得 (Application.StartupPath)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

using DevExpress.XtraEditors;

namespace DXApplication2
{
  internal class MainViewModel
  {
    public string AppStartPath
    {
      get;
      set;
    }
  }
  
  public partial class Form1 : XtraForm
  {
    internal MainViewModel _viewModel;

    public Form1()
    {
      _viewModel = new MainViewModel();
      InitializeComponent();
      InitializeViewModel();
      InitializeBindings();
    }

    internal void InitializeViewModel()
    {
      //
      // http://msdn.microsoft.com/ja-jp/library/system.windows.forms.application.startuppath(v=vs.110).aspx
      //
      _viewModel.AppStartPath = Application.StartupPath;
    }

    internal void InitializeBindings()
    {
      var txtBinding = new Binding("EditValue", _viewModel, "AppStartPath");
      textEdit1.DataBindings.Add(txtBinding);
    }
  }
}