mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Basic dialog infrastructure
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
<FontFamily x:Key="ZMHIcons">Assets/ZMH_Icons.ttf#ZMHIcons</FontFamily>
|
||||
<FontFamily x:Key="SegoeMDL2">Segoe MDL2 Assets</FontFamily>
|
||||
|
||||
<BooleanToVisibilityConverter x:Key="BoolToVis" />
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
|
||||
@@ -4,19 +4,17 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:ZuneModdingHelper.Controls"
|
||||
xmlns:zmhm="clr-namespace:ZuneModdingHelper.Messages"
|
||||
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Themes/Zune.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<d:UserControl.DataContext>
|
||||
<zmhm:DialogViewModel/>
|
||||
</d:UserControl.DataContext>
|
||||
|
||||
<Border Background="#AFFFFFFF">
|
||||
<Border MaxHeight="408" MaxWidth="530" Padding="32">
|
||||
<Border MaxHeight="400" MaxWidth="528" Padding="32" SnapsToDevicePixels="True"
|
||||
VerticalAlignment="Center">
|
||||
<Border.Background>
|
||||
<LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
|
||||
<GradientStop Color="#FFFFFF" Offset="0"/>
|
||||
@@ -34,15 +32,17 @@
|
||||
<Rectangle Height="5" Width="109" Margin="0,-16,0,0"
|
||||
VerticalAlignment="Top" HorizontalAlignment="Left"
|
||||
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}"/>
|
||||
|
||||
<ContentControl Grid.Row="1" Content="TEst"
|
||||
HorizontalAlignment="{Binding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{Binding VerticalContentAlignment}" />
|
||||
<StackPanel Grid.Row="1">
|
||||
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" Margin="0,0,0,12"
|
||||
Foreground="{StaticResource ZuneLightTextBrush}"/>
|
||||
<ContentControl x:Name="InnerPresenter" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Content="CANCEL" Grid.Row="2" HorizontalAlignment="Right"
|
||||
FontSize="12" Height="24"
|
||||
<Button Content="OK" Grid.Row="2" HorizontalAlignment="Right"
|
||||
FontSize="12" Height="24" Visibility="{Binding ShowPrimaryButton, Converter={StaticResource BoolToVis}}"
|
||||
Style="{StaticResource ActionButtonStyle}"/>
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Xml.Linq;
|
||||
using ZuneModdingHelper.Messages;
|
||||
|
||||
namespace ZuneModdingHelper.Controls
|
||||
@@ -20,6 +22,42 @@ namespace ZuneModdingHelper.Controls
|
||||
set => SetValue(DialogViewModelProperty, value);
|
||||
}
|
||||
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]
|
||||
private string _description;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _showPrimaryButton;
|
||||
|
||||
[ObservableProperty]
|
||||
private int? _height;
|
||||
}
|
||||
|
||||
public partial class ProgressDialogViewModel : DialogViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private double _progress;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isIndeterminate;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,14 @@ namespace ZuneModdingHelper.Pages
|
||||
|
||||
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"
|
||||
}));
|
||||
}
|
||||
|
||||
private static bool TryGetModFromControl(object sender, out Mod mod)
|
||||
{
|
||||
mod = (sender as System.Windows.FrameworkElement)?.DataContext as Mod;
|
||||
return mod is not null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,5 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="/Controls/PathButton.xaml"/>
|
||||
<ResourceDictionary Source="/Controls/TextButton.xaml"/>
|
||||
<ResourceDictionary Source="/Controls/ZuneLightDialog.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
Reference in New Issue
Block a user