问题描述
大家好,
去年我创建了一个框架,用于在WinC中以MVC风格开发类似国际象棋/棋盘格的游戏。我现在正试图将此框架移动到UWP / XAML(接近WPF)。我有一些使用XAML的经验,但想知道创建UI的最佳方式是什么。
在我的WinForms项目中,我有一个PictureBoxes的2D数组,其中玩家可以使用内置的拖放功能来移动。
在XAML中没有PictureBoxes所以我需要提出另一种方法。一个想法是使网格具有多个单元格/面板/类似。理想情况下,每个单元应具有背景颜色(即黑色或白色),然后可能是所讨论的部件的图像(例如,王或典当)。然后,images / cells / panels / ...需要可拖动,以便可以在棋盘上移动棋子。请注意,检查板可以具有不同的长度,例如4 * 9的正方形,并且长度在Constants类中设置。换句话说,Grid / similar必须在代码隐藏中设置其行数/列数。
我应该如何做到这一点?我不需要数学,只是使用什么控件以及如何在代码隐藏中动态创建它们并且能够执行拖放操作。
非常感谢!
Petter
Hi all,
Last year I created a framework for developing chess/checker-like games in WinForms, in MVC style. I am now trying to move this framework to UWP/XAML (close to WPF). I have some experience with XAML, but wonder what the best way to create the UI would be.
In my WinForms project I had a 2D array of PictureBoxes, which the player could move around using the built-in drag'n'drop functionality.
In XAML there are no PictureBoxes so I need to come up with another approach. One idea is to have a Grid with a number of cells/panels/similiar. Each "cell" should ideally have a background color (ie black or white) and then possibly an image of the piece in question (eg king or pawn). The images/cells/panels/... then need to be draggable, so that the pieces can be moved over the checkboard. Note that the checkboard can have different lenghts, such as 4*9 squares, and that the lengths are set in a Constants class. In other words, the Grid/similar must have its number of rows/columns set in codebehind.
Any ideas of how I should do this? I don't need the math, just what controls to use and perhaps how to create them dynamically in codebehind and to be able to perform drag'n'drop.
Many thanks!
Petter
推荐答案
这篇关于如何在UWP / WPF / XAML中创建检查板UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!