by Anonymous » 22 Aug 2025, 04:57
Beispielprojekt hier
https://github.com/hassstrictlyff14/timelinecomponent
Ich versuche, eine zoombare/scrollbare "Timeline" -Komponente zu erstellen. Diese Komponente hat eine ElementSource, die ich an eine Beobachtung bindet. Es verfügt außerdem über eine ItemsControl mit einer Leinwand, die die "Zeitblöcke" enthält. Ich bemerkte jedoch, dass es beim Hinzufügen eines neuen Artikels immer zum oberen links der Leinwand geht. Wenn ich die Sammlung zoome /scrolle oder ein weiteres Element hinzufüge, geht es in die richtige Position.
Code: Select all
< /code>
// called after item is added to draw the blocks
private void PositionBlocks()
{
// Clear and re-add so Canvas Left/Width apply
if (PART_Items == null || ItemsSource == null) return;
// Ensure containers are realized before we set positions
PART_Items.UpdateLayout();
foreach (var item in ItemsSource)
{
var container = (FrameworkElement)PART_Items.ItemContainerGenerator.ContainerFromItem(item);
if (container is null) continue; // is null for last item added when initially added
if (item is TimelineBlock b)
{
var left = XOf(b.Start);
var width = Math.Max(1.0, (b.End - b.Start).Ticks * PixelsPerTick);
Canvas.SetLeft(container, left);
Canvas.SetTop(container, 12); // row baseline for blocks
container.Width = width;
container.Height = 24;
}
}
}
Der GitHub -Link zeigt ein Beispiel des Problems an.
Beispielprojekt hier https://github.com/hassstrictlyff14/timelinecomponent
Ich versuche, eine zoombare/scrollbare "Timeline" -Komponente zu erstellen. Diese Komponente hat eine ElementSource, die ich an eine Beobachtung bindet. Es verfügt außerdem über eine ItemsControl mit einer Leinwand, die die "Zeitblöcke" enthält. Ich bemerkte jedoch, dass es beim Hinzufügen eines neuen Artikels immer zum oberen links der Leinwand geht. Wenn ich die Sammlung zoome /scrolle oder ein weiteres Element hinzufüge, geht es in die richtige Position.[code]
< /code>
// called after item is added to draw the blocks
private void PositionBlocks()
{
// Clear and re-add so Canvas Left/Width apply
if (PART_Items == null || ItemsSource == null) return;
// Ensure containers are realized before we set positions
PART_Items.UpdateLayout();
foreach (var item in ItemsSource)
{
var container = (FrameworkElement)PART_Items.ItemContainerGenerator.ContainerFromItem(item);
if (container is null) continue; // is null for last item added when initially added
if (item is TimelineBlock b)
{
var left = XOf(b.Start);
var width = Math.Max(1.0, (b.End - b.Start).Ticks * PixelsPerTick);
Canvas.SetLeft(container, left);
Canvas.SetTop(container, 12); // row baseline for blocks
container.Width = width;
container.Height = 24;
}
}
}
[/code]
Der GitHub -Link zeigt ein Beispiel des Problems an.