diff --git a/ZuneModdingHelper/AppWindow.xaml b/ZuneModdingHelper/AppWindow.xaml index 47a93ab..f4f3367 100644 --- a/ZuneModdingHelper/AppWindow.xaml +++ b/ZuneModdingHelper/AppWindow.xaml @@ -5,6 +5,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:zmh="clr-namespace:ZuneModdingHelper" xmlns:zmhc="clr-namespace:ZuneModdingHelper.Controls" + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" + xmlns:b="clr-namespace:ZuneModdingHelper.Behaviors" mc:Ignorable="d" WindowStyle="None" Title="{x:Static zmh:App.Title}" Height="450" Width="800" WindowStartupLocation="CenterScreen"> @@ -74,18 +76,31 @@ + Style="{StaticResource PivotButtonStyle}" /> + Style="{StaticResource PivotButtonStyle}" /> + Style="{StaticResource PivotButtonStyle}" /> - - - Howdy! + + + + + + + + + + + + + + + + diff --git a/ZuneModdingHelper/AppWindow.xaml.cs b/ZuneModdingHelper/AppWindow.xaml.cs index b70615e..ee96693 100644 --- a/ZuneModdingHelper/AppWindow.xaml.cs +++ b/ZuneModdingHelper/AppWindow.xaml.cs @@ -1,8 +1,10 @@ using System; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Interop; +using ZuneModdingHelper.Pages; namespace ZuneModdingHelper { @@ -12,18 +14,23 @@ namespace ZuneModdingHelper public partial class AppWindow { private IntPtr _windowHandle; - private int _selectedPivotIdx = 0; + private int _selectedPivotIdx = -1; + + private readonly Type[] _pages = [typeof(ModsPage), typeof(Border), typeof(Border)]; public AppWindow() { - Loaded += AppWindow_Loaded; InitializeComponent(); + Pivot.Loaded += Pivot_Loaded; } - private void AppWindow_Loaded(object sender, RoutedEventArgs e) + private void Pivot_Loaded(object sender, RoutedEventArgs e) { + foreach (var item in Pivot.Children.OfType()) + item.Checked += PivotButton_Checked; + // Select MODS tab - var pivotItem = (ToggleButton)Pivot.Children[_selectedPivotIdx]; + var pivotItem = (ToggleButton)Pivot.Children[0]; pivotItem.IsChecked = true; } @@ -59,12 +66,17 @@ namespace ZuneModdingHelper if (newIdx == _selectedPivotIdx) return; - var pivotItem = (ToggleButton)Pivot.Children[_selectedPivotIdx]; - pivotItem.IsChecked = false; + if (_selectedPivotIdx >= 0 && _selectedPivotIdx < Pivot.Children.Count) + { + var oldPivotItem = (ToggleButton)Pivot.Children[_selectedPivotIdx]; + oldPivotItem.IsChecked = false; + } _selectedPivotIdx = newIdx; - pivotItem = (ToggleButton)Pivot.Children[_selectedPivotIdx]; - pivotItem.IsChecked = true; + var newPivotItem = (ToggleButton)Pivot.Children[_selectedPivotIdx]; + newPivotItem.IsChecked = true; + + ContentFrame.Content = Activator.CreateInstance(_pages[_selectedPivotIdx]); } } } diff --git a/ZuneModdingHelper/Behaviors/ContentControlExtensions.cs b/ZuneModdingHelper/Behaviors/ContentControlExtensions.cs new file mode 100644 index 0000000..978f650 --- /dev/null +++ b/ZuneModdingHelper/Behaviors/ContentControlExtensions.cs @@ -0,0 +1,45 @@ +using System; +using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media.Animation; + +namespace ZuneModdingHelper.Behaviors; + +static class ContentControlExtensions +{ + /// + /// https://stackoverflow.com/questions/10831965/begin-animation-when-contentcontrol-content-is-changed + /// + public static readonly DependencyProperty ContentChangedAnimationProperty = DependencyProperty.RegisterAttached( + "ContentChangedAnimation", typeof(Storyboard), typeof(ContentControlExtensions), new PropertyMetadata(default(Storyboard), ContentChangedAnimationPropertyChangedCallback)); + + public static void SetContentChangedAnimation(DependencyObject element, Storyboard value) + { + element.SetValue(ContentChangedAnimationProperty, value); + } + + public static Storyboard GetContentChangedAnimation(DependencyObject element) + { + return (Storyboard)element.GetValue(ContentChangedAnimationProperty); + } + + private static void ContentChangedAnimationPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) + { + if (dependencyObject is not ContentControl contentControl) + throw new Exception("Can only be applied to a ContentControl"); + + var propertyDescriptor = DependencyPropertyDescriptor.FromProperty(ContentControl.ContentProperty, + typeof(ContentControl)); + + propertyDescriptor.RemoveValueChanged(contentControl, ContentChangedHandler); + propertyDescriptor.AddValueChanged(contentControl, ContentChangedHandler); + } + + private static void ContentChangedHandler(object sender, EventArgs eventArgs) + { + var animateObject = (FrameworkElement)sender; + var storyboard = GetContentChangedAnimation(animateObject); + storyboard.Begin(animateObject); + } +} diff --git a/ZuneModdingHelper/Pages/ModsPage.xaml b/ZuneModdingHelper/Pages/ModsPage.xaml new file mode 100644 index 0000000..31cc1ae --- /dev/null +++ b/ZuneModdingHelper/Pages/ModsPage.xaml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ZuneModdingHelper/Pages/ModsPage.xaml.cs b/ZuneModdingHelper/Pages/ModsPage.xaml.cs new file mode 100644 index 0000000..0b6ca22 --- /dev/null +++ b/ZuneModdingHelper/Pages/ModsPage.xaml.cs @@ -0,0 +1,46 @@ +using Microsoft.AppCenter.Analytics; +using OwlCore.AbstractUI.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using ZuneModCore; + +namespace ZuneModdingHelper.Pages +{ + /// + /// Interaction logic for ModsPage.xaml + /// + public partial class ModsPage : UserControl + { + public ModsPage() + { + InitializeComponent(); + ModList.ItemsSource = Mod.AvailableMods; + } + + private async void ModInstallButton_Click(object sender, RoutedEventArgs e) + { + if (sender is FrameworkElement elem && elem.DataContext is Mod mod) + { + } + } + + private async void ModResetButton_Click(object sender, RoutedEventArgs e) + { + if (sender is FrameworkElement elem && elem.DataContext is Mod mod) + { + } + } + } +}