You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
3.1 KiB
99 lines
3.1 KiB
using AIK.ViewModels;
|
|
using AIK.ViewModels.CommonViewModel;
|
|
using AIK.ViewModels.RemoteGeneration;
|
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
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;
|
|
|
|
namespace AIK.Views.MenuPages.RemoteGeneration
|
|
{
|
|
/// <summary>
|
|
/// RemoteGenerationPage.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class RemoteGenerationPage : UserControl
|
|
{
|
|
public IReadOnlyList<string> LetterIndexes { get; } =
|
|
Enumerable.Range('A', 26).Select(c => ((char)c).ToString()).ToArray();
|
|
|
|
public RemoteGenerationPage()
|
|
{
|
|
InitializeComponent();
|
|
//if (!IsInDesignMode())
|
|
//{
|
|
// DataContext = Ioc.Default.GetService<KeyModelViewModel>();
|
|
//}
|
|
DataContext = Ioc.Default.GetService<RemoteGenerationViewModel>();
|
|
}
|
|
|
|
private static bool IsInDesignMode()
|
|
{
|
|
return DesignerProperties.GetIsInDesignMode(new DependencyObject());
|
|
}
|
|
|
|
private void LetterIndexButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (sender is not Button button || button.Content is not string letter)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var groupContainer = FindVisualChildren<FrameworkElement>(BrandGroupsList)
|
|
.FirstOrDefault(element => string.Equals(element.Tag as string, letter, StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (groupContainer == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ScrollGroupToTop(groupContainer);
|
|
}
|
|
|
|
private void ScrollGroupToTop(FrameworkElement groupContainer)
|
|
{
|
|
if (!groupContainer.IsLoaded)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var groupPosition = groupContainer.TransformToAncestor(scrList).Transform(new Point(0, 0));
|
|
var targetOffset = scrList.VerticalOffset + groupPosition.Y;
|
|
scrList.ScrollToVerticalOffset(Math.Max(0, targetOffset));
|
|
}
|
|
|
|
private static IEnumerable<T> FindVisualChildren<T>(DependencyObject parent) where T : DependencyObject
|
|
{
|
|
if (parent == null)
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
var childCount = VisualTreeHelper.GetChildrenCount(parent);
|
|
for (var index = 0; index < childCount; index++)
|
|
{
|
|
var child = VisualTreeHelper.GetChild(parent, index);
|
|
if (child is T typedChild)
|
|
{
|
|
yield return typedChild;
|
|
}
|
|
|
|
foreach (var descendant in FindVisualChildren<T>(child))
|
|
{
|
|
yield return descendant;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|