mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix #656 listviewbase selected item sync
This commit is contained in:
@@ -22,17 +22,18 @@ internal sealed partial class AutoHeightBehavior : BehaviorBase<FrameworkElement
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
protected override bool Initialize()
|
||||
{
|
||||
UpdateElement();
|
||||
AssociatedObject.SizeChanged += sizeChangedEventHandler;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDetaching()
|
||||
protected override bool Uninitialize()
|
||||
{
|
||||
AssociatedObject.SizeChanged -= sizeChangedEventHandler;
|
||||
base.OnDetaching();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
|
||||
@@ -22,17 +22,19 @@ internal sealed partial class AutoWidthBehavior : BehaviorBase<FrameworkElement>
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
protected override bool Initialize()
|
||||
{
|
||||
UpdateElement();
|
||||
AssociatedObject.SizeChanged += sizeChangedEventHandler;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDetaching()
|
||||
protected override bool Uninitialize()
|
||||
{
|
||||
AssociatedObject.SizeChanged -= sizeChangedEventHandler;
|
||||
base.OnDetaching();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||
|
||||
@@ -28,19 +28,19 @@ internal sealed class ComboBoxExtendsContentIntoTitleBarWorkaroundBehavior : Beh
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnAssociatedObjectLoaded()
|
||||
protected override bool Initialize()
|
||||
{
|
||||
AssociatedObject.DropDownOpened += dropDownOpenedHandler;
|
||||
AssociatedObject.DropDownClosed += dropDownClosedHandler;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDetaching()
|
||||
protected override bool Uninitialize()
|
||||
{
|
||||
AssociatedObject.DropDownOpened -= dropDownOpenedHandler;
|
||||
AssociatedObject.DropDownClosed -= dropDownClosedHandler;
|
||||
|
||||
base.OnDetaching();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnDropDownOpened(object? sender, object e)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.Behaviors;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
|
||||
namespace Snap.Hutao.Control.Behavior;
|
||||
|
||||
internal sealed class SelectedItemInViewBehavior : BehaviorBase<ListViewBase>
|
||||
{
|
||||
protected override bool Initialize()
|
||||
{
|
||||
if (AssociatedObject.SelectedItem is { } item)
|
||||
{
|
||||
AssociatedObject.ScrollIntoView(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -94,18 +94,4 @@ internal static partial class EnumerableExtension
|
||||
string result = string.Join(separator, collection);
|
||||
return result.Length > 0 ? result : string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Concatenates each element from the collection into single string.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of array elements.</typeparam>
|
||||
/// <param name="collection">Collection to convert. Cannot be <see langword="null"/>.</param>
|
||||
/// <param name="separator">Delimiter between elements in the final string.</param>
|
||||
/// <param name="defaultValue">A string to be returned if collection has no elements.</param>
|
||||
/// <returns>Converted collection into string.</returns>
|
||||
public static string ToString<T>(this IEnumerable<T> collection, char separator, string defaultValue)
|
||||
{
|
||||
string result = string.Join(separator, collection);
|
||||
return result.Length > 0 ? result : defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,6 @@ internal sealed partial class AnnouncementService : IAnnouncementService
|
||||
{
|
||||
if (AnnouncementRegex.PermanentActivityTimeRegex.Match(announcement.Content) is { Success: true } permanent)
|
||||
{
|
||||
|
||||
announcement.StartTime = versionUpdateTime;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -68,15 +68,9 @@
|
||||
ItemsSource="{Binding Monsters}"
|
||||
SelectedItem="{Binding Selected, Mode=TwoWay}"
|
||||
SelectionMode="Single">
|
||||
<ListView.GroupStyle>
|
||||
<GroupStyle>
|
||||
<GroupStyle.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Style="{StaticResource BaseTextBlockStyle}" Text="{Binding Key}"/>
|
||||
</DataTemplate>
|
||||
</GroupStyle.HeaderTemplate>
|
||||
</GroupStyle>
|
||||
</ListView.GroupStyle>
|
||||
<mxi:Interaction.Behaviors>
|
||||
<shcb:SelectedItemInViewBehavior/>
|
||||
</mxi:Interaction.Behaviors>
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
@@ -188,6 +182,9 @@
|
||||
ItemsSource="{Binding Monsters}"
|
||||
SelectedItem="{Binding Selected, Mode=TwoWay}"
|
||||
SelectionMode="Single">
|
||||
<mxi:Interaction.Behaviors>
|
||||
<shcb:SelectedItemInViewBehavior/>
|
||||
</mxi:Interaction.Behaviors>
|
||||
<GridView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<ItemsWrapGrid Orientation="Horizontal"/>
|
||||
|
||||
Reference in New Issue
Block a user