[英]Add new control and resize container to fit accordingly
I'm working on a Blackjack game for school and I need a container, which will be containing Image controls. 我正在为学校玩二十一点游戏,我需要一个容器,其中将包含图像控件。
I want to have a container in which Image controls will be created (through code) to house the images for the cards which the player has hit. 我想要一个容器,用于在其中创建图像控件(通过代码)来容纳玩家所击中的卡的图像。 This can be up to 9 cards when working with a single deck, like I am.
像我一样,在单个卡座上最多可以使用9张卡片。
As for my question: What would be the easiest/lowest impact way to create each Image control so that the center across all of the controls are aligned with the center of my "hand" Image controls? 关于我的问题:创建每个Image控件以使所有控件的中心与我的“手” Image控件的中心对齐的最简单/影响最小的方法是什么?
Here's a quick illustration with what I mean: 这是我的意思的简要说明:
So basically: If the amount of cards is uneven (1,3,5,7 or 9), the center of the middle card is centered above the hand. 基本上就是这样:如果纸牌数量不均匀(1、3、5、7或9),则中间纸牌的中心位于手的上方。
If the amount of cards is even (2,4,6 or 8), the space in between the 2 middle cards is centered above the hand. 如果纸牌数量为偶数(2、4、6或8),则两张中间纸牌之间的空间将居中于手上方。
I'd do something like this, replacing Rectangles with Images as appropriate: 我会做这样的事情,将“矩形”替换为“图像”:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Rectangle Width="100"
Height="100"
Fill="Blue" />
<Rectangle Width="100"
Height="100"
Fill="Green" />
<Rectangle Width="100"
Height="100"
Fill="Blue" />
<Rectangle Width="100"
Height="100"
Fill="Green" />
<Rectangle Width="100"
Height="100"
Fill="Blue" />
<Rectangle Width="100"
Height="100"
Fill="Green" />
<Rectangle Width="100"
Height="100"
Fill="Blue" />
</StackPanel>
<StackPanel Grid.Row="1"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Rectangle Width="100"
Height="100"
Fill="Red" />
<Rectangle Width="100"
Height="100"
Fill="Black" />
</StackPanel>
</Grid>
I've manually filled the StackPanels where normally you'd bind their ItemsSource properties to ObservableCollection(s). 我已经手动填充了StackPanels,通常您会在其中将其ItemsSource属性绑定到ObservableCollection(s)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.