mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Added entrance animation to home page
This commit is contained in:
@@ -0,0 +1,75 @@
|
|||||||
|
using Microsoft.Xaml.Behaviors;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media.Animation;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
|
||||||
|
namespace ZuneModdingHelper.Behaviors
|
||||||
|
{
|
||||||
|
// https://stackoverflow.com/a/5910833
|
||||||
|
public class FadeAnimateItemsBehavior : Behavior<ListBox>
|
||||||
|
{
|
||||||
|
public DoubleAnimation Animation { get; set; }
|
||||||
|
public TimeSpan Tick { get; set; }
|
||||||
|
|
||||||
|
protected override void OnAttached()
|
||||||
|
{
|
||||||
|
base.OnAttached();
|
||||||
|
AssociatedObject.Loaded += AssociatedObject_Loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
IEnumerable<ListBoxItem> items;
|
||||||
|
if (AssociatedObject.ItemsSource == null)
|
||||||
|
{
|
||||||
|
items = AssociatedObject.Items.Cast<ListBoxItem>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var itemsSource = AssociatedObject.ItemsSource;
|
||||||
|
if (itemsSource is INotifyCollectionChanged)
|
||||||
|
{
|
||||||
|
var collection = itemsSource as INotifyCollectionChanged;
|
||||||
|
collection.CollectionChanged += (s, cce) =>
|
||||||
|
{
|
||||||
|
if (cce.Action == NotifyCollectionChangedAction.Add)
|
||||||
|
{
|
||||||
|
var itemContainer = AssociatedObject.ItemContainerGenerator.ContainerFromItem(cce.NewItems[0]) as ListBoxItem;
|
||||||
|
itemContainer.BeginAnimation(ListBoxItem.OpacityProperty, Animation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
ListBoxItem[] itemsSub = new ListBoxItem[AssociatedObject.Items.Count];
|
||||||
|
for (int i = 0; i < itemsSub.Length; i++)
|
||||||
|
{
|
||||||
|
itemsSub[i] = AssociatedObject.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
|
||||||
|
}
|
||||||
|
items = itemsSub;
|
||||||
|
}
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
item.Opacity = 0;
|
||||||
|
}
|
||||||
|
var enumerator = items.GetEnumerator();
|
||||||
|
if (enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
DispatcherTimer timer = new() { Interval = Tick };
|
||||||
|
timer.Tick += (s, timerE) =>
|
||||||
|
{
|
||||||
|
var item = enumerator.Current;
|
||||||
|
item.BeginAnimation(ListBoxItem.OpacityProperty, Animation);
|
||||||
|
if (!enumerator.MoveNext())
|
||||||
|
{
|
||||||
|
timer.Stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
timer.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
xmlns:local="clr-namespace:ZuneModdingHelper"
|
xmlns:local="clr-namespace:ZuneModdingHelper"
|
||||||
xmlns:core="clr-namespace:ZuneModCore;assembly=ZuneModCore"
|
xmlns:core="clr-namespace:ZuneModCore;assembly=ZuneModCore"
|
||||||
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
|
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
|
||||||
|
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
|
xmlns:b="clr-namespace:ZuneModdingHelper.Behaviors"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="{x:Static local:App.Title}" Height="450" Width="800" WindowStartupLocation="CenterScreen"
|
Title="{x:Static local:App.Title}" Height="450" Width="800" WindowStartupLocation="CenterScreen"
|
||||||
Loaded="Window_Loaded">
|
Loaded="Window_Loaded">
|
||||||
@@ -131,6 +133,14 @@
|
|||||||
</Border>
|
</Border>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
|
|
||||||
|
<i:Interaction.Behaviors>
|
||||||
|
<b:FadeAnimateItemsBehavior Tick="0:0:0.05">
|
||||||
|
<b:FadeAnimateItemsBehavior.Animation>
|
||||||
|
<DoubleAnimation From="0" To="1" Duration="0:0:0.3"/>
|
||||||
|
</b:FadeAnimateItemsBehavior.Animation>
|
||||||
|
</b:FadeAnimateItemsBehavior>
|
||||||
|
</i:Interaction.Behaviors>
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
<Border Grid.Row="1" BorderThickness="0,1,0,0" BorderBrush="{StaticResource MahApps.Brushes.Control.Border}">
|
<Border Grid.Row="1" BorderThickness="0,1,0,0" BorderBrush="{StaticResource MahApps.Brushes.Control.Border}">
|
||||||
|
|||||||
@@ -34,20 +34,21 @@ namespace ZuneModdingHelper
|
|||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
// https://github.com/Arlodotexe/OwlCore/issues/1
|
||||||
OwlCore.Threading.SetPrimarySynchronizationContext(System.Threading.SynchronizationContext.Current!);
|
OwlCore.Threading.SetPrimarySynchronizationContext(System.Threading.SynchronizationContext.Current!);
|
||||||
OwlCore.Threading.SetPrimaryThreadInvokeHandler(RunOnUI);
|
OwlCore.Threading.SetPrimaryThreadInvokeHandler(RunOnUI);
|
||||||
|
|
||||||
ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
|
ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode;
|
||||||
ThemeManager.Current.SyncTheme();
|
ThemeManager.Current.SyncTheme();
|
||||||
|
|
||||||
|
ModList.ItemsSource = Mod.AvailableMods;
|
||||||
|
ZuneInstallDirBox.Text = Mod.ZuneInstallDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async System.Threading.Tasks.Task RunOnUI(Action action) => await Dispatcher.BeginInvoke(action);
|
private async System.Threading.Tasks.Task RunOnUI(Action action) => await Dispatcher.BeginInvoke(action);
|
||||||
|
|
||||||
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
private async void Window_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ModList.ItemsSource = Mod.AvailableMods;
|
|
||||||
ZuneInstallDirBox.Text = Mod.ZuneInstallDir;
|
|
||||||
|
|
||||||
// Show a warning if Zune is running
|
// Show a warning if Zune is running
|
||||||
Process[] procs = Process.GetProcessesByName("Zune");
|
Process[] procs = Process.GetProcessesByName("Zune");
|
||||||
string zuneExePath = Path.Combine(Mod.ZuneInstallDir, "Zune.exe");
|
string zuneExePath = Path.Combine(Mod.ZuneInstallDir, "Zune.exe");
|
||||||
|
|||||||
Reference in New Issue
Block a user