-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSaveBrowser.xaml.cs
More file actions
75 lines (61 loc) · 2.49 KB
/
FileSaveBrowser.xaml.cs
File metadata and controls
75 lines (61 loc) · 2.49 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
67
68
69
70
71
72
73
74
75
using System.IO;
using System.Reflection;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using Ookii.Dialogs.Wpf;
namespace QuickBrake {
public partial class FileSaveBrowser {
public delegate void DlgOnChange(string NewPath);
public DlgOnChange OnChange;
public FileSaveBrowser() {
InitializeComponent();
}
public static DirectoryInfo ExecutingLocation() => ExecutingApplication().Directory;
public static FileInfo ExecutingApplication() => new FileInfo(Assembly.GetExecutingAssembly().Location);
public string Filter = "Any File (*.*)|*.*";
void BrowseButton_Click(object Sender, RoutedEventArgs E) {
VistaSaveFileDialog SaveDialog = new VistaSaveFileDialog {
AddExtension = true,
Filter = Filter,
FilterIndex = 0,
FileName = SelectedSavePath,
InitialDirectory = ExecutingLocation().FullName,
OverwritePrompt = true,
Title = "Pick a save location",
ValidateNames = true
};
switch (SaveDialog.ShowDialog()) {
case true:
PathTextBox.Text = SaveDialog.FileName;
OnChange?.Invoke(PathTextBox.Text);
break;
}
}
#region Dependency Properties
public string SelectedSavePath {
get => (string)GetValue(SelectedSavePathProperty);
set {
SetValue(SelectedSavePathProperty, value);
OnChange?.Invoke(value);
}
}
public static readonly DependencyProperty SelectedSavePathProperty =
DependencyProperty.Register(
"SelectedSavePath",
typeof(string),
typeof(FileSaveBrowser),
new FrameworkPropertyMetadata(SelectedSavePathChanged) {
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
static void SelectedSavePathChanged(DependencyObject D, DependencyPropertyChangedEventArgs E) {
((FileSaveBrowser)D).PathTextBox.Text = E.NewValue.ToString();
}
#endregion
void PathTextBox_LostKeyboardFocus(object Sender, KeyboardFocusChangedEventArgs E) {
SelectedSavePath = PathTextBox.Text;
OnChange?.Invoke(PathTextBox.Text);
}
}
}