47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using Avalonia.Controls;
|
||
using Avalonia.Markup.Xaml;
|
||
using Project_Periodensystem.Controller;
|
||
using Project_Periodensystem.View.Components;
|
||
|
||
namespace Project_Periodensystem.View
|
||
{
|
||
public partial class MainWindow : Window
|
||
{
|
||
private readonly PeriodensystemController _controller;
|
||
|
||
public MainWindow()
|
||
{
|
||
InitializeComponent();
|
||
_controller = new PeriodensystemController();
|
||
DataContext = _controller;
|
||
PopulateCanvas();
|
||
}
|
||
|
||
private void InitializeComponent()
|
||
=> AvaloniaXamlLoader.Load(this);
|
||
|
||
private void PopulateCanvas()
|
||
{
|
||
// Holt den Canvas aus dem XAML (muss existieren!)
|
||
var canvas = this.FindControl<Canvas>("PeriodicCanvas");
|
||
if (canvas == null)
|
||
return;
|
||
|
||
foreach (var element in _controller.Elements)
|
||
{
|
||
// Neues Tile für jedes Element
|
||
var tile = new ElementTile
|
||
{
|
||
DataContext = element
|
||
};
|
||
|
||
// Position setzen: Column × 80px, Row × 80px
|
||
Canvas.SetLeft(tile, element.Column * 80);
|
||
Canvas.SetTop(tile, element.Row * 80);
|
||
|
||
canvas.Children.Add(tile);
|
||
}
|
||
}
|
||
}
|
||
}
|