Basic dialog infrastructure

This commit is contained in:
Yoshi Askharoun
2024-05-16 00:58:18 -05:00
parent fe65698a24
commit 8e7a3a4e70
6 changed files with 77 additions and 18 deletions
+2
View File
@@ -16,6 +16,8 @@
<FontFamily x:Key="ZMHIcons">Assets/ZMH_Icons.ttf#ZMHIcons</FontFamily> <FontFamily x:Key="ZMHIcons">Assets/ZMH_Icons.ttf#ZMHIcons</FontFamily>
<FontFamily x:Key="SegoeMDL2">Segoe MDL2 Assets</FontFamily> <FontFamily x:Key="SegoeMDL2">Segoe MDL2 Assets</FontFamily>
<BooleanToVisibilityConverter x:Key="BoolToVis" />
</ResourceDictionary> </ResourceDictionary>
</Application.Resources> </Application.Resources>
</Application> </Application>
+14 -14
View File
@@ -4,19 +4,17 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZuneModdingHelper.Controls" xmlns:local="clr-namespace:ZuneModdingHelper.Controls"
xmlns:zmhm="clr-namespace:ZuneModdingHelper.Messages"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources> <d:UserControl.DataContext>
<ResourceDictionary> <zmhm:DialogViewModel/>
<ResourceDictionary.MergedDictionaries> </d:UserControl.DataContext>
<ResourceDictionary Source="/Themes/Zune.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Border Background="#AFFFFFFF"> <Border Background="#AFFFFFFF">
<Border MaxHeight="408" MaxWidth="530" Padding="32"> <Border MaxHeight="400" MaxWidth="528" Padding="32" SnapsToDevicePixels="True"
VerticalAlignment="Center">
<Border.Background> <Border.Background>
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFFFFF" Offset="0"/> <GradientStop Color="#FFFFFF" Offset="0"/>
@@ -34,15 +32,17 @@
<Rectangle Height="5" Width="109" Margin="0,-16,0,0" <Rectangle Height="5" Width="109" Margin="0,-16,0,0"
VerticalAlignment="Top" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalAlignment="Left"
Fill="{StaticResource ZuneHorizontalGradientAlt}"/> Fill="{StaticResource ZuneHorizontalGradientAlt}"/>
<TextBlock Text="{Binding ViewModel.Title}" d:Text="WINDOWS LIVE ID" FontSize="28" Margin="0,-10,0,0" <TextBlock Text="{Binding Title}" d:Text="WINDOWS LIVE ID" FontSize="28" Margin="0,-10,0,0"
Foreground="{StaticResource ZuneMediumTextBrush}"/> Foreground="{StaticResource ZuneMediumTextBrush}"/>
<ContentControl Grid.Row="1" Content="TEst" <StackPanel Grid.Row="1">
HorizontalAlignment="{Binding HorizontalContentAlignment}" <TextBlock Text="{Binding Description}" TextWrapping="Wrap" Margin="0,0,0,12"
VerticalAlignment="{Binding VerticalContentAlignment}" /> Foreground="{StaticResource ZuneLightTextBrush}"/>
<ContentControl x:Name="InnerPresenter" />
</StackPanel>
<Button Content="CANCEL" Grid.Row="2" HorizontalAlignment="Right" <Button Content="OK" Grid.Row="2" HorizontalAlignment="Right"
FontSize="12" Height="24" FontSize="12" Height="24" Visibility="{Binding ShowPrimaryButton, Converter={StaticResource BoolToVis}}"
Style="{StaticResource ActionButtonStyle}"/> Style="{StaticResource ActionButtonStyle}"/>
</Grid> </Grid>
@@ -1,5 +1,7 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Xml.Linq;
using ZuneModdingHelper.Messages; using ZuneModdingHelper.Messages;
namespace ZuneModdingHelper.Controls namespace ZuneModdingHelper.Controls
@@ -20,6 +22,42 @@ namespace ZuneModdingHelper.Controls
set => SetValue(DialogViewModelProperty, value); set => SetValue(DialogViewModelProperty, value);
} }
public static readonly DependencyProperty DialogViewModelProperty = DependencyProperty.Register( public static readonly DependencyProperty DialogViewModelProperty = DependencyProperty.Register(
nameof(ViewModel), typeof(DialogViewModel), typeof(ZuneLightDialog), new PropertyMetadata(null)); nameof(ViewModel), typeof(DialogViewModel), typeof(ZuneLightDialog), new PropertyMetadata(ViewModelChanged));
private static void ViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not ZuneLightDialog dialog || e.NewValue is not DialogViewModel vm)
return;
dialog.DataContext = vm;
if (vm.Height is not null)
dialog.Height = vm.Height.Value;
if (vm is ProgressDialogViewModel)
{
var progressBar = new ProgressBar();
Binding progValueBinding = new()
{
Source = vm,
Path = new PropertyPath(nameof(ProgressDialogViewModel.Progress)),
Mode = BindingMode.OneWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
progressBar.SetBinding(ProgressBar.ValueProperty, progValueBinding);
Binding progIndetBinding = new()
{
Source = vm,
Path = new PropertyPath(nameof(ProgressDialogViewModel.IsIndeterminate)),
Mode = BindingMode.OneWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
progressBar.SetBinding(ProgressBar.IsIndeterminateProperty, progIndetBinding);
dialog.InnerPresenter.Content = progressBar;
}
}
} }
} }
@@ -13,10 +13,19 @@ public partial class DialogViewModel : ObservableObject
[ObservableProperty] [ObservableProperty]
private string _description; private string _description;
[ObservableProperty]
private bool _showPrimaryButton;
[ObservableProperty]
private int? _height;
} }
public partial class ProgressDialogViewModel : DialogViewModel public partial class ProgressDialogViewModel : DialogViewModel
{ {
[ObservableProperty] [ObservableProperty]
private double _progress; private double _progress;
[ObservableProperty]
private bool _isIndeterminate;
} }
+13 -2
View File
@@ -18,9 +18,14 @@ namespace ZuneModdingHelper.Pages
private void ResetButton_Click(object sender, System.Windows.RoutedEventArgs e) private void ResetButton_Click(object sender, System.Windows.RoutedEventArgs e)
{ {
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(new DialogViewModel if (!TryGetModFromControl(sender, out var mod))
return;
WeakReferenceMessenger.Default.Send(new ShowDialogMessage(new ProgressDialogViewModel
{ {
Title = "RESET" Title = "RESETTING MOD",
IsIndeterminate = true,
Description = $"Preparing to reset '{mod.Title}'...",
})); }));
} }
@@ -31,5 +36,11 @@ namespace ZuneModdingHelper.Pages
Title = "APPLY" Title = "APPLY"
})); }));
} }
private static bool TryGetModFromControl(object sender, out Mod mod)
{
mod = (sender as System.Windows.FrameworkElement)?.DataContext as Mod;
return mod is not null;
}
} }
} }
-1
View File
@@ -6,6 +6,5 @@
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Controls/PathButton.xaml"/> <ResourceDictionary Source="/Controls/PathButton.xaml"/>
<ResourceDictionary Source="/Controls/TextButton.xaml"/> <ResourceDictionary Source="/Controls/TextButton.xaml"/>
<ResourceDictionary Source="/Controls/ZuneLightDialog.xaml"/>
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>