40 行
1.2 KiB
C#
40 行
1.2 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
|
|
namespace UndoTree;
|
|
|
|
internal partial class UndoTreeReviewWindow : Window
|
|
{
|
|
public UndoTreeReviewWindow(UndoTreeReviewViewModel model)
|
|
{
|
|
InitializeComponent();
|
|
DataContext = model;
|
|
Rows.AddHandler(ScrollViewer.ScrollChangedEvent, new ScrollChangedEventHandler((_, _) => AlignHeader()));
|
|
Rows.SizeChanged += (_, _) => AlignHeader();
|
|
}
|
|
|
|
void Apply_Click(object sender, RoutedEventArgs e) => DialogResult = true;
|
|
|
|
void AlignHeader()
|
|
{
|
|
if (Descendant<ScrollViewer>(Rows) is { } viewer)
|
|
Header.Margin = new Thickness(0, 0, Math.Max(0, Rows.ActualWidth - viewer.ViewportWidth), 0);
|
|
}
|
|
|
|
static T? Descendant<T>(DependencyObject parent) where T : DependencyObject
|
|
{
|
|
for (var index = 0; index < VisualTreeHelper.GetChildrenCount(parent); index++)
|
|
{
|
|
var child = VisualTreeHelper.GetChild(parent, index);
|
|
if (child is T match)
|
|
return match;
|
|
|
|
if (Descendant<T>(child) is { } nested)
|
|
return nested;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|