Add folder picker button

This commit is contained in:
Yoshi Askharoun
2024-05-17 21:55:07 -05:00
parent 7794c03c93
commit e431dd9a9e
2 changed files with 44 additions and 8 deletions
+9 -4
View File
@@ -7,8 +7,11 @@
xmlns:zmhs="clr-namespace:ZuneModdingHelper.Services"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Unloaded="SettingsPage_Unloaded"
DataContext="{x:Static zmhs:Settings.Default}">
Unloaded="SettingsPage_Unloaded">
<d:UserControl.DataContext>
<local:SettingsViewModel/>
</d:UserControl.DataContext>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel>
<TextBlock Style="{StaticResource ZuneBodyTextBlockStyle}">
@@ -16,8 +19,10 @@
</TextBlock>
<TextBlock Text="Choose the directory where the Zune software is installed." Margin="0,8"
Style="{StaticResource ZuneBodyTextBlockStyle}" />
<TextBox VerticalAlignment="Top"
Text="{Binding ZuneInstallDir}"/>
<TextBox Text="{Binding Settings.ZuneInstallDir}"/>
<Button Content="LOCATE" HorizontalAlignment="Left" Margin="0,8,0,0"
Visibility="{Binding FolderPickerVisibility, Mode=OneTime}"
Click="LocateZuneButton_Click"/>
</StackPanel>
</ScrollViewer>
</UserControl>
+35 -4
View File
@@ -1,4 +1,5 @@
using System.Windows;
using Microsoft.WindowsAPICodePack.Dialogs;
using System.Windows;
using System.Windows.Controls;
using ZuneModdingHelper.Services;
@@ -9,15 +10,45 @@ namespace ZuneModdingHelper.Pages
/// </summary>
public partial class SettingsPage : UserControl
{
public SettingsPage()
public SettingsPage(Settings settings)
{
ViewModel = new()
{
Settings = settings,
FolderPickerVisibility = CommonFileDialog.IsPlatformSupported
? Visibility.Visible : Visibility.Collapsed,
};
DataContext = ViewModel;
InitializeComponent();
DataContext = Settings.Default;
}
private SettingsViewModel ViewModel { get; }
private async void SettingsPage_Unloaded(object sender, RoutedEventArgs e)
{
await Settings.Default.SaveAsync();
await ViewModel.Settings.SaveAsync();
}
private void LocateZuneButton_Click(object sender, RoutedEventArgs e)
{
CommonOpenFileDialog dialog = new()
{
IsFolderPicker = true,
DefaultDirectory = ViewModel.Settings.ZuneInstallDir
};
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
{
ViewModel.Settings.ZuneInstallDir = dialog.FileName;
}
}
}
internal class SettingsViewModel
{
public Settings Settings { get; init; }
public Visibility FolderPickerVisibility { get; init; }
}
}