我想为 Windows 手机制作一个简单的棋盘游戏,上面有 5 x 5 方形瓷砖。显然我希望它有一个动态界面,其中瓷砖的宽度和高度属性是根据用户的手机分辨率设置的。就此而言,在我的XAML
代码中,我使用 * 将我的页面宽度划分为 5 列(相对大小),并且在每一列中我有一个堆栈面板,我向其中添加了 5 个按钮。像这样:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<StackPanel x:Name="ButtonsCol0" Grid.Column="0">
<Button Background="AliceBlue"
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
</Button>
<Button
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
</Button>
<Button
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
</Button>
<Button
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
</Button>
<Button
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
</Button>
</StackPanel>
(我StackPanel
每列还有 4 个以上)
现在的问题是我希望瓷砖具有方形(相同的高度和宽度),我发现了这个问题,这就是我添加的原因:
MinWidth="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"
MinHeight="{Binding ActualWidth, RelativeSource={RelativeSource Self}}">
到我的按钮,这似乎工作,但是当我运行代码时,结果是这样的:
请帮忙... :)