2 using System.Collections.Generic;
6 using System.Windows.Controls;
7 using System.Windows.Data;
8 using System.Windows.Documents;
9 using System.Windows.Input;
10 using System.Windows.Media;
11 using System.Windows.Media.Imaging;
12 using System.Windows.Navigation;
13 using System.Windows.Shapes;
15 namespace UserControls
18 /// UCFileSelectTextBox.xaml の相互作用ロジック
20 public partial class UCFileSelectTextBox : System.Windows.Controls.UserControl
22 public UCFileSelectTextBox()
24 InitializeComponent();
25 textBoxFileName.DragEnter += new DragEventHandler(textBoxFileName_DragEnter);
27 textBoxFileName.PreviewDragEnter += new DragEventHandler(textBoxFileName_PreviewDragEnter);
28 textBoxFileName.PreviewDrop += new DragEventHandler(textBoxFileName_PreviewDrop);
30 BitmapImage myBitmapImage = new BitmapImage();
32 //myBitmapImage.BeginInit();
33 //myBitmapImage.UriSource = new Uri(@"dir.JPG");
34 //myBitmapImage.EndInit();
36 //imgFileDirSelecter.Source = myBitmapImage;
41 void textBoxFileName_PreviewDrop(object sender, DragEventArgs e)
43 //throw new NotImplementedException();
44 textBox_Drop(sender, e);
47 void textBoxFileName_PreviewDragEnter(object sender, DragEventArgs e)
49 //throw new NotImplementedException();
50 textBox_DragEnter(sender, e);
53 void textBoxFileName_DragEnter(object sender, DragEventArgs e)
55 //throw new NotImplementedException();
56 textBox_DragEnter(sender, e);
63 return textBoxFileName.Text;
68 textBoxFileName.Text = value;
72 private void button_Click(object sender, RoutedEventArgs e)
74 //TODO:フォルダー選択かっこ悪いのでカスタムを作成したい
75 System.Windows.Forms.FolderBrowserDialog fbd =
76 new System.Windows.Forms.FolderBrowserDialog();
78 fbd.SelectedPath = textBoxFileName.Text;
79 System.Windows.Forms.DialogResult result = fbd.ShowDialog();
81 if (result == System.Windows.Forms.DialogResult.OK)
83 if (sender == buttonFileDirSelecter)
85 textBoxFileName.Text = fbd.SelectedPath;
90 private void textBox_MouseEnter(object sender, MouseEventArgs e)
92 TextBox textBox = (TextBox)sender;
93 if (textBox.Text == "" || textBox.Text == null)
95 textBox.ToolTip = null;
99 textBox.ToolTip = textBox.Text;
103 private void textBox_Drop(object sender, DragEventArgs e)
105 //TODO:ドラッグアンドドロップ対応したのだが動かないので調査が必要
107 if (e.Effects == System.Windows.DragDropEffects.Copy)
109 TextBox textBox = (TextBox)sender;
111 textBox.Text = e.Data.GetData(System.Windows.DataFormats.FileDrop).ToString();
114 // ファイルドロップした場合のみ処理
115 if (e.Data.GetDataPresent(DataFormats.FileDrop))
117 foreach (string fileName in (string[])e.Data.GetData(DataFormats.FileDrop))
119 TextBox textBox = (TextBox)sender;
120 textBox.Text = fileName;
128 private void textBox_DragEnter(object sender, DragEventArgs e)
130 //textBoxFrom.Text = "test";
131 if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)
132 || e.Data.GetDataPresent(System.Windows.DataFormats.Text)
133 || e.Data.GetDataPresent(System.Windows.DataFormats.UnicodeText))
135 e.Effects = System.Windows.DragDropEffects.Copy;