我會用結合,以顯示你的採集卡 - 一個選項是使用ItemsControl
有Canvas
爲ItemsPanel
,並設置ItemContainerStyle
每個卡位。就像:
<ItemsControl ItemsSource="{Binding CardCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding CardImage}" Width="{Binding CardWidth}" Height="{Binding CardHeight}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left" Value="{Binding CardX}" />
<Setter Property="Canvas.Top" Value="{Binding CardY}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
謝謝,我只是這樣做,只適用於重新調整大小,我創建了一個從Canvas派生的自定義面板。是否可以指示畫布自動調整內容大小,以便使用分配給它的空間顯示所有內容? –