-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSaveBrowser.xaml.cs
More file actions
66 lines (54 loc) · 2.21 KB
/
FileSaveBrowser.xaml.cs
File metadata and controls
66 lines (54 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using Ookii.Dialogs.Wpf;
namespace QuickPlay {
public partial class FileSaveBrowser {
public FileSaveBrowser() {
InitializeComponent();
}
public static DirectoryInfo ExecutingLocation() => ExecutingApplication().Directory;
public static FileInfo ExecutingApplication() => new FileInfo(Assembly.GetExecutingAssembly().Location);
void BrowseButton_Click(object Sender, RoutedEventArgs E) {
VistaSaveFileDialog SaveDialog = new VistaSaveFileDialog {
AddExtension = true,
DefaultExt = ".txt",
Filter = "Text File (*.txt)|*.txt|Any File (*.*)|*.*",
FilterIndex = 0,
FileName = SelectedPath,
InitialDirectory = ExecutingLocation().FullName,
OverwritePrompt = true,
Title = "Pick a save location",
ValidateNames = true
};
switch (SaveDialog.ShowDialog()) {
case true:
PathTextBox.Text = SaveDialog.FileName;
break;
}
}
#region Dependency Properties
public string SelectedPath {
get => (string)GetValue(SelectedPathProperty);
set => SetValue(SelectedPathProperty, value);
}
public static readonly DependencyProperty SelectedPathProperty =
DependencyProperty.Register(
"SelectedPath",
typeof(string),
typeof(FileSaveBrowser),
new FrameworkPropertyMetadata(SelectedPathChanged) {
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
static void SelectedPathChanged(DependencyObject D, DependencyPropertyChangedEventArgs E) {
((FileSaveBrowser)D).PathTextBox.Text = E.NewValue.ToString();
}
#endregion
void PathTextBox_LostKeyboardFocus(object Sender, KeyboardFocusChangedEventArgs E) {
SelectedPath = PathTextBox.Text;
}
}
}