fix: Aufsicht-Zeilen im Stundenplan deutlich schmaler als Stundenblöcke

UniformGrid erzwingt für alle Zellen dieselbe, vom größten Kind
bestimmte Höhe - eine Aufsicht-Zeile konnte dadurch nie schmaler
werden als eine Stundenzeile, auch nicht durch kleinere Inhalte.

Cells/WeekItems werden jetzt zusätzlich zeilenweise in neue
GridRows/WeekRows-Collections gruppiert (TimetableRowItem/
WeekRowItem, je eine eigene, ganz normal bindbare RowHeight -
Aufsicht-Zeilen 22px statt 46px/76px bei normalen Stunden-/
Kopfzeilen). Innerhalb jeder Zeile bleibt UniformGrid Columns="6"
für die Spaltenaufteilung. Grid.RowDefinitions ließ sich dafür nicht
per {Binding} setzen (Avalonia lehnt jede Bindungsform dafür mit
AVLN3000 ab) - deshalb dieser Umweg über echte Unterzeilen statt
eines einzelnen Grids mit dynamischer RowDefinitions-Bindung.

$parent[ItemsControl]-Bindings in den Zell-Templates mussten auf
$parent[ItemsControl;1] angepasst werden, da durch die neue
Verschachtelung sonst das innere Zeilen-ItemsControl statt des
äußeren (mit TimetableViewModel als DataContext) getroffen wird.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-18 09:14:14 +02:00
co-authored by Claude Sonnet 5
parent 4510c56bb4
commit a36b1d1d40
3 changed files with 191 additions and 104 deletions
@@ -442,6 +442,19 @@ public sealed class TimetableViewModelTests
Assert.DoesNotContain(vm.Cells, c => c.IsSupervisionRow);
}
[Fact]
public void Load_AufsichtEingetragen_BekommtSchmalereZeilenhoeheAlsStundenzeilen()
{
var duties = new FakeSupervisionDuties();
duties.Add(new SupervisionDuty { Weekday = DayOfWeek.Monday, AfterPeriod = 2, Location = "Pausenhof" });
var vm = BuildViewModel(new FakeTimetableSlots(), new FakeGroups([]), supervisionDuties: duties);
var row = vm.GridRows.Single(r => r.Cells.Any(c => c.IsSupervisionRow && c.Text.Contains("n. 2.")));
Assert.Equal(22, row.RowHeight);
Assert.Contains(vm.GridRows, r => r.RowHeight == 46); // normale Stundenzeilen bleiben unverändert
}
// ── Aufsicht + Vertretung im Wochenraster ────────────────────────────────
[Fact]
@@ -457,6 +470,19 @@ public sealed class TimetableViewModelTests
Assert.False(mondayCell.IsSubstitutionSupervision);
}
[Fact]
public void Load_Wochenraster_AufsichtBekommtSchmalereZeilenhoeheAlsStundenzeilen()
{
var duties = new FakeSupervisionDuties();
duties.Add(new SupervisionDuty { Weekday = DayOfWeek.Monday, AfterPeriod = 2, Location = "Pausenhof" });
var vm = BuildViewModel(new FakeTimetableSlots(), new FakeGroups([]), supervisionDuties: duties);
var row = vm.WeekRows.Single(r => r.Cells.Any(c => c.IsSupervisionRow && c.Text.Contains("n. 2.")));
Assert.Equal(22, row.RowHeight);
Assert.Contains(vm.WeekRows, r => r.RowHeight == 76);
}
[Fact]
public void Load_Wochenraster_VertretungsaufsichtUeberschreibtRegulaereAnzeige()
{
@@ -45,6 +45,7 @@ public partial class TimetableViewModel : ObservableObject
{
private const int FirstPeriod = 1;
private const int LastPeriod = 10;
private const int GridColumns = 6; // Label/Kopf-Spalte + 5 Wochentage (Mo-Fr)
private static readonly DayOfWeek[] Weekdays =
[DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday];
private static readonly string[] WeekdayColorPalette =
@@ -70,6 +71,15 @@ public partial class TimetableViewModel : ObservableObject
public ObservableCollection<TodaySpecialAssignmentItem> TodaySpecialAssignments { get; } = [];
public ObservableCollection<UpcomingExamItem> UpcomingExams { get; } = [];
/// Cells/WeekItems zeilenweise gruppiert (GridColumns Zellen je Zeile), zusätzlich zur
/// flachen Liste - Grundlage für die zeilenweise Höhensteuerung in der View (Aufsicht-Zeilen
/// deutlich schmaler als Stunden-/Kopfzeilen). Grid.RowDefinitions lässt sich in Avalonia
/// nicht per {Binding} setzen (Compiler lehnt jede Binding-Form dafür ab, siehe
/// AVLN3000-Fehler „Unable to find suitable setter or adder for property RowDefinitions“) -
/// deshalb hier stattdessen echte Unterzeilen mit je eigener, ganz normal bindbarer Height.
public ObservableCollection<TimetableRowItem> GridRows { get; } = [];
public ObservableCollection<WeekRowItem> WeekRows { get; } = [];
[ObservableProperty] private int _activeTabIndex;
[ObservableProperty] private string _todayLabel = "";
[ObservableProperty] private string _weekRangeLabel = "";
@@ -325,6 +335,10 @@ public partial class TimetableViewModel : ObservableObject
}
AddWeekSupervisionRowIfAny(period, dutiesByPeriod, substitutionsThisWeek, dateByWeekday);
}
WeekRows.Clear();
foreach (var rowCells in WeekItems.Chunk(GridColumns))
WeekRows.Add(new WeekRowItem(rowCells));
}
private void AddWeekSupervisionRowIfAny(int afterPeriod, ILookup<int, SupervisionDuty> dutiesByPeriod,
@@ -409,6 +423,10 @@ public partial class TimetableViewModel : ObservableObject
}
AddGridSupervisionRowIfAny(period, dutiesByPeriod);
}
GridRows.Clear();
foreach (var rowCells in Cells.Chunk(GridColumns))
GridRows.Add(new TimetableRowItem(rowCells));
}
/// <summary>Aufsicht wird nur in den Einstellungen gepflegt (siehe SettingsView) — im
@@ -571,6 +589,18 @@ public class TimetableCellItem
};
}
/// <summary>
/// Eine Zeile im Bearbeiten-Raster (GridColumns Zellen). Aufsicht-Zeilen bekommen eine deutlich
/// schmalere RowHeight als normale Kopf-/Stundenzeilen - eine echte, per Height ganz normal
/// bindbare Eigenschaft je Unterzeile statt eines vollflächigen UniformGrid-Rasters, das allen
/// Zeilen zwangsläufig dieselbe Höhe geben würde.
/// </summary>
public class TimetableRowItem(IReadOnlyList<TimetableCellItem> cells)
{
public IReadOnlyList<TimetableCellItem> Cells { get; } = cells;
public double RowHeight { get; } = cells[0].IsSupervisionRow ? 22 : 46;
}
/// <summary>Zelle im schreibgeschützten Wochenraster der "Heute"-Ansicht.</summary>
public class WeekCellItem
{
@@ -671,6 +701,13 @@ public class WeekCellItem
};
}
/// <summary>Zeile im Wochenraster - siehe TimetableRowItem, dieselbe Rolle für WeekItems.</summary>
public class WeekRowItem(IReadOnlyList<WeekCellItem> cells)
{
public IReadOnlyList<WeekCellItem> Cells { get; } = cells;
public double RowHeight { get; } = cells[0].IsSupervisionRow ? 22 : 76;
}
public class HoursWarningItem(string groupName, int assigned, int expected)
{
public string GroupName { get; } = groupName;
@@ -133,13 +133,23 @@
ToolTip.Tip="Einstellungen (Ferien, Aufsichten, Stundenraster)"/>
</Grid>
<ItemsControl ItemsSource="{Binding WeekItems}">
<!-- Zeilenweise (WeekRows) statt eines einzigen flachen UniformGrid: so kann jede
Zeile ihre eigene Höhe haben (RowHeight je WeekRowItem) - Aufsicht-Zeilen
deutlich schmaler als Stunden-/Kopfzeilen. Grid.RowDefinitions lässt sich in
Avalonia nicht per {Binding} setzen (AVLN3000 "Unable to find suitable setter
or adder"), daher dieser Umweg statt eines einzelnen Grids mit dynamischer
RowDefinitions-Bindung. Die innere UniformGrid Columns="6" bleibt unverändert
für die Spaltenaufteilung innerhalb je einer Zeile. -->
<ItemsControl ItemsSource="{Binding WeekRows}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:WeekRowItem">
<ItemsControl ItemsSource="{Binding Cells}" Height="{Binding RowHeight}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate><UniformGrid Columns="6"/></ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:WeekCellItem">
<Grid Margin="2" MinHeight="76">
<Grid Margin="2">
<Border Classes="weekheader" Classes.today="{Binding IsToday}" CornerRadius="4"
IsVisible="{Binding IsHeader}">
<TextBlock Text="{Binding Text}" FontWeight="SemiBold" FontSize="12" Opacity="0.75"
@@ -152,10 +162,11 @@
FontSize="10" FontWeight="SemiBold" Opacity="0.55" TextWrapping="Wrap"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Border Classes="supervisioncell" Classes.substitution="{Binding IsSubstitutionSupervision}"
CornerRadius="4" Padding="4" IsVisible="{Binding IsSupervisionCell}"
CornerRadius="4" Padding="4,1" IsVisible="{Binding IsSupervisionCell}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Text="{Binding SupervisionLocation}" FontSize="10" Foreground="White"
HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap"
<TextBlock Text="{Binding SupervisionLocation}" FontSize="9" Foreground="White"
HorizontalAlignment="Center" VerticalAlignment="Center"
TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"
IsVisible="{Binding HasSupervision}"/>
</Border>
<Border Classes="timetablecell" Classes.assigned="{Binding IsAssigned}"
@@ -163,7 +174,7 @@
<Button Background="{Binding ColorHex}" IsVisible="{Binding IsAssigned}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch" CornerRadius="6" Padding="6"
Command="{Binding $parent[ItemsControl].((vm:TimetableViewModel)DataContext).OpenGroupCommand}"
Command="{Binding $parent[ItemsControl;1].((vm:TimetableViewModel)DataContext).OpenGroupCommand}"
CommandParameter="{Binding GroupId}">
<StackPanel Spacing="1">
<TextBlock FontSize="11" FontWeight="Bold" Foreground="White" TextWrapping="Wrap">
@@ -193,6 +204,9 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Border Background="{DynamicResource SystemControlBackgroundAltHighBrush}"
CornerRadius="8" Padding="16" IsVisible="{Binding HoursWarnings.Count}">
@@ -237,13 +251,19 @@
<ContentPage Header="Bearbeiten">
<ScrollViewer>
<StackPanel Margin="32,20,32,28" Spacing="10">
<ItemsControl ItemsSource="{Binding Cells}">
<!-- Zeilenweise (GridRows) statt eines flachen UniformGrid, siehe Kommentar im
Wochenraster oben (Heute-Tab) - gleicher Grund (Grid.RowDefinitions lässt sich
nicht per {Binding} setzen). -->
<ItemsControl ItemsSource="{Binding GridRows}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:TimetableRowItem">
<ItemsControl ItemsSource="{Binding Cells}" Height="{Binding RowHeight}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate><UniformGrid Columns="6"/></ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:TimetableCellItem">
<Grid Margin="2" MinHeight="46">
<Grid Margin="2">
<TextBlock Text="{Binding Text}" IsVisible="{Binding IsHeader}"
FontWeight="SemiBold" FontSize="12" Opacity="0.6"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
@@ -253,11 +273,12 @@
<TextBlock Text="{Binding Text}" IsVisible="{Binding IsSupervisionRow}"
FontSize="10" FontWeight="SemiBold" Opacity="0.55" TextWrapping="Wrap"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Border Classes="supervisioncell" CornerRadius="4" Padding="4"
<Border Classes="supervisioncell" CornerRadius="4" Padding="4,1"
IsVisible="{Binding IsSupervisionCell}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Text="{Binding SupervisionLocation}" FontSize="10" Foreground="White"
HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap"
<TextBlock Text="{Binding SupervisionLocation}" FontSize="9" Foreground="White"
HorizontalAlignment="Center" VerticalAlignment="Center"
TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"
IsVisible="{Binding HasSupervision}"/>
</Border>
<Border Classes="timetablecell" Classes.assigned="{Binding IsAssigned}"
@@ -267,7 +288,7 @@
IsVisible="{Binding IsAssigned}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalContentAlignment="Center" CornerRadius="6"
Command="{Binding $parent[ItemsControl].((vm:TimetableViewModel)DataContext).EditCellCommand}"
Command="{Binding $parent[ItemsControl;1].((vm:TimetableViewModel)DataContext).EditCellCommand}"
CommandParameter="{Binding}">
<TextBlock Text="{Binding Text}" FontSize="11" Foreground="White"
TextWrapping="Wrap" TextAlignment="Center"/>
@@ -276,7 +297,7 @@
IsVisible="{Binding !IsAssigned}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
HorizontalContentAlignment="Center" Background="Transparent"
Command="{Binding $parent[ItemsControl].((vm:TimetableViewModel)DataContext).EditCellCommand}"
Command="{Binding $parent[ItemsControl;1].((vm:TimetableViewModel)DataContext).EditCellCommand}"
CommandParameter="{Binding}"/>
<Border Background="#D85A30" CornerRadius="8" Padding="5,1"
IsVisible="{Binding HasBadge}"
@@ -289,6 +310,9 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
</ContentPage>