diff --git a/AvaloniaSample/MainWindow.axaml.cs b/AvaloniaSample/MainWindow.axaml.cs index 4733a81..8d4bbb2 100644 --- a/AvaloniaSample/MainWindow.axaml.cs +++ b/AvaloniaSample/MainWindow.axaml.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -16,10 +17,12 @@ namespace AvaloniaSample InitializeComponent(); this.AttachDevTools(); + double tileAspectRation = 0.5; + var tilePanel = new TilePanelViewModel() { - ItemHeight = 100, - ItemWidth = 250, + ItemHeight = 130, + ItemWidth = 230, MaximumRowsOrColumns = 3, Tiles = new ObservableCollection() { @@ -66,6 +69,18 @@ namespace AvaloniaSample } }; + var itemsPanel = this.FindControl("ItemsControl"); + + itemsPanel.GetObservable(BoundsProperty).Subscribe(x => + { + var width = x.Width; + var itemWidth = width / tilePanel.MaximumRowsOrColumns; + var itemHeight = itemWidth * tileAspectRation; + + tilePanel.ItemHeight = itemHeight; + tilePanel.ItemWidth = itemWidth; + }); + DataContext = tilePanel; }