Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
FileFolderPathControl.xaml.cs
1using System.IO;
4using Microsoft.Win32;
6
8{
12 public partial class FileFolderPathControl : UserControl
13 {
18 {
19 Files,
20 Folders
21 }
22
23 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
29 {
30 InitializeComponent();
31 }
32
33 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
43
47 public static readonly DependencyProperty FileFolderSelectionModeProperty = DependencyProperty.Register(nameof(FileFolderSelectionMode), typeof(FileFolderSelectionModes), typeof(FileFolderPathControl), new PropertyMetadata(FileFolderSelectionModes.Files));
48
49 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50
54 public string FileFolderPath
55 {
56 get { return (string)GetValue(FileFolderPathProperty); }
57 set { SetValue(FileFolderPathProperty, value); }
58 }
59
63 public static readonly DependencyProperty FileFolderPathProperty = DependencyProperty.Register(nameof(FileFolderPath), typeof(string), typeof(FileFolderPathControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFileFolderPathChanged));
64
65 private static void OnFileFolderPathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
66 {
68 control.calculateResolvedFileFolderPath();
69 }
70
71 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
72
77 {
78 get { return (string)GetValue(RootFolderForRelativePathsProperty); }
79 set { SetValue(RootFolderForRelativePathsProperty, value); }
80 }
81
85 public static readonly DependencyProperty RootFolderForRelativePathsProperty = DependencyProperty.Register(nameof(RootFolderForRelativePaths), typeof(string), typeof(FileFolderPathControl), new PropertyMetadata("", OnRootFolderForRelativePathsChanged));
86
87 private static void OnRootFolderForRelativePathsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
88 {
90 if (!string.IsNullOrEmpty(e.NewValue as string))
91 {
92 control.FileFolderPath = FilePathHelper.MakePathRelative(control.ResolvedFileFolderPath, e.NewValue as string);
93 }
94 else
95 {
96 // If the root folder is empty, we just leave the FileFolderPath as is
97 }
98 control.calculateResolvedFileFolderPath();
99 }
100
101 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
102
108 {
109 get { return (string)GetValue(ResolvedFileFolderPathProperty); }
110 set { SetValue(ResolvedFileFolderPathProperty, value); }
111 }
112
116 public static readonly DependencyProperty ResolvedFileFolderPathProperty = DependencyProperty.Register(nameof(ResolvedFileFolderPath), typeof(string), typeof(FileFolderPathControl), new PropertyMetadata(""));
117
118 private void calculateResolvedFileFolderPath()
119 {
120 if (!string.IsNullOrEmpty(RootFolderForRelativePaths) && !FilePathHelper.IsPathFullyQualified(FileFolderPath))
121 {
122 // Construct absolute path
123 ResolvedFileFolderPath = Path.GetFullPath(Path.Combine(RootFolderForRelativePaths, FileFolderPath));
124 }
125 else if(string.IsNullOrEmpty(RootFolderForRelativePaths) && !FilePathHelper.IsPathFullyQualified(FileFolderPath))
126 {
127 // Use relative path as is
129 }
130 else
131 {
132 // Use absolute path
134 }
135
136 if (FileFolderSelectionMode == FileFolderSelectionModes.Folders && !FilePathHelper.IsPathDirectory(ResolvedFileFolderPath))
137 {
138 ResolvedFileFolderPath = Path.GetDirectoryName(ResolvedFileFolderPath);
139 }
140 }
141
142 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
143
148 {
149 get { return (string)GetValue(OpenFileDialogFilterProperty); }
150 set { SetValue(OpenFileDialogFilterProperty, value); }
151 }
152
156 public static readonly DependencyProperty OpenFileDialogFilterProperty = DependencyProperty.Register(nameof(OpenFileDialogFilter), typeof(string), typeof(FileFolderPathControl), new PropertyMetadata("All files (*.*)|*.*"));
157
158 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
159
165 {
166 get { return (bool)GetValue(ShouldShowFullPathProperty); }
167 set { SetValue(ShouldShowFullPathProperty, value); }
168 }
169
173 public static readonly DependencyProperty ShouldShowFullPathProperty = DependencyProperty.Register(nameof(ShouldShowFullPath), typeof(bool), typeof(FileFolderPathControl), new PropertyMetadata(false));
174
175 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
176
177 private void btn_browse_Click(object sender, RoutedEventArgs e)
178 {
179 string tmpFileFolderPath = string.Empty;
181 {
182 case FileFolderSelectionModes.Files:
183 {
184 OpenFileDialog openFileDialog = new OpenFileDialog();
185 openFileDialog.InitialDirectory = Path.GetDirectoryName(ResolvedFileFolderPath);
186 openFileDialog.FileName = FileFolderPath;
187 openFileDialog.Filter = OpenFileDialogFilter;
188 if (openFileDialog.ShowDialog() == true)
189 {
190 tmpFileFolderPath = openFileDialog.FileName;
191 }
192 break;
193 }
194 case FileFolderSelectionModes.Folders:
195 {
196 OpenFolderDialog openFolderDialog = new OpenFolderDialog();
197 openFolderDialog.InitialDirectory = ResolvedFileFolderPath;
198 openFolderDialog.FolderName = FileFolderPath;
199 if (openFolderDialog.ShowDialog() == true)
200 {
201 tmpFileFolderPath = openFolderDialog.FolderName;
202 }
203 break;
204 }
205 default: break;
206 }
207
208 if (!string.IsNullOrEmpty(tmpFileFolderPath))
209 {
210 if (!string.IsNullOrEmpty(RootFolderForRelativePaths))
211 {
212 FileFolderPath = FilePathHelper.MakePathRelative(tmpFileFolderPath, RootFolderForRelativePaths);
213 }
214 else
215 {
216 FileFolderPath = tmpFileFolderPath;
217 }
218 }
219 }
220
221 private void btn_showFullPath_Click(object sender, RoutedEventArgs e)
222 {
224 }
225 }
226}
static readonly DependencyProperty OpenFileDialogFilterProperty
Dependency property for the OpenFileDialogFilter.
static readonly DependencyProperty ShouldShowFullPathProperty
Dependency property for the ShouldShowFullPath.
bool ShouldShowFullPath
Indicating whether the ResolvedFileFolderPath should be shown.
static readonly DependencyProperty FileFolderPathProperty
Dependency property for the FileFolderPath.
FileFolderPathControl()
Constructor of the FileFolderPathControl
static readonly DependencyProperty RootFolderForRelativePathsProperty
Dependency property for the RootFolderForRelativePaths.
static readonly DependencyProperty FileFolderSelectionModeProperty
Dependency property for the FileFolderSelectionMode.
string ResolvedFileFolderPath
Resolved file or folder path (absolute path).
string FileFolderPath
Current file or folder path (can be relative or absolute).
string RootFolderForRelativePaths
Root folder used for relative paths.
FileFolderSelectionModes FileFolderSelectionMode
Current selection mode for the file/folder path control.
static readonly DependencyProperty ResolvedFileFolderPathProperty
Dependency property for the ResolvedFileFolderPath.
FileFolderSelectionModes
Available selection modes for the file/folder path control.