How do I Draw a Chessboard using XAML? - c#

I am working on a project that requires me to develop an application using the Universal Windows Platform (UWP). I have no prior knowledge of developing UWP apps and XAML is completely new to me. Thankfully however, I am competent at writing in C#.
The project I am working on involves recreating the Tafl Board games - Hnefatafl, Brandubh, Tablut, etc.
Now, while I'm fairly confident in my ability to create the underlying logic for the game, I find myself bamboozled when it comes to creating the interface using XAML.
Several different chessboards will need to be rendered: 7x7, 9x9 and 11x11.
So my question is two-fold.
How do I create a chessboard in XAML that will scale appropriately to different window/display sizes and be able to be backed by a grid behind the scenes (i.e. The application can detect which square of the board is touched, etc)
How do I go about rendering a different board depending on the game type selected?
Apologies if this is a terrible question but googling hasn't helped me a whole lot and StackOverflow has always been a great source of information.

You might want to try out the RelativePanel control and use different coloured rectangles for the tiles. This would resize for different screen sizes.

I hope you finally got an answer to this that led you in the right direction. If you didn't here are some ideas that might narrow your research terms and get your going. I'd give you working samples but youd did mention it is for a school project :).
Using a listbox and manupulating the base style can be a relatively
good way to go, and very reusable. This also fulfills your
requirement of knowing the tile currently selected as the listbox
already handles that. I used this technique for a Sudoku board that
had alternating colors for the different regions.
Create a UserControl with properties for the number of columns and
rows you need for your board and then dynamically add the rows and
columns to the grid. If your game model has a list of tiles and
each tile has a column and row property that can be mapped to the
column and row indices of the grid, you could potentially bind to it
quite easily.
Create a custom control that handles the columns,
rows and other aspects of the board itself in c# and the rendering
in XAML. I personally shy away from this just because the existing
controls are already so flexible that with enough ingenuity you can
create what you need with out of the box controls.

Related

What WPF control to use for a series of images (like Netflix, Hulu, etc..)?

New to .Net and Visual Studio. Quickly learning. As my first application, I am building a program similar to Netflix and Hulu (without the streaming part). Coming from a web background, I'd use tables and divs to accomplish what I am trying to do.
What component would I use to create a series of thumbnails (as you would find on Netflix) of the movie / TV show. Provided an image below as an example.
It would continue on with horizontal scroll. I understand this would be non trivial and I'm not expecting a direct answer. However, I am resourceful person and only would need to be pointed in the right direction.
Thank you.
You should use an ItemsControl variant which could be ListView with ScrollViewer.
Or, a WrapPanel with ScrollViewer.
Or, a UniformGrid.
Apply scrolling support using Animation.

Create an editable table using WPF controls

Maybe this is not the right forum for my question, but I'll try anyway.
I am creating an application where I want the user to be able to fill in values in a table/matrix. The values are then going to be saved to a database I have set up. I want to build this application using Windows Presentation Foundation (WPF). I watched the following video on youtube:
https://www.youtube.com/watch?v=_i4mYXSaD4w and it shows very well what features I want my own application to have. The problem is, the example in the video is made in Winforms...
So, my question, which can be split into three parts, is:
Is there a way to build something equal, similar or better, in WPF?
What/which control(s) should I use? Grid? DataGrid?
How do I use this control?
I am new to WPF, and do not have a good picture of what controls to use. I have read many questions about WPF's DataGrid on StackOverflow as well as other QnA's, but I couldn't understand how to do what I wanted, or even if it was possible. Therefore, I'm very thankful to anyone who can explain and lead me onto the right track.
I suggest you to read this article: http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples

Create an Object Editor in C# for WinForms

I need to find, or create an editor that will handle text and images as objects. For instance I have a 3 line string of text, to be able to move it around and position it within a canvas, also the ability to add an image, and possibly resize it within that canvas. and take the result, and save it, whether I get the the offsets and positions manually, of each of the objects (preferable) , or get the entire canvas as an image, to be able to save and print.
Rulers would be great... Im not trying to re-create Photoshop, but the idea is similar.
I will be doing this in a C# WinForms application, it does seem however that a WPF solution might be better suited, and I think I can have a WPF control within winforms...
Any direction or advice would be greatly appreciated.
Forget winforms. It doesn't support anything. Your best bet is to do it in WPF and if you need, you can integrate it into an existing winforms application via the ElementHost.
Please see my similar answers/samples about this:
https://stackoverflow.com/a/15580293/643085
https://stackoverflow.com/a/15469477/643085
https://stackoverflow.com/a/15821573/643085
Also, see this example with support for zoom, panning and resizing functionality:
https://stackoverflow.com/a/16947081/643085
They're all MVVM based and have some interesting features.
You can easily customize these samples and add ANY type of elements:
images,
geometries,
usable interactive UI elements with functionality (TextBoxes, ComboBoxes, whatever),
text,
videos,
FlowDocuments,
or whatever that's visible on screen)
by adding additional data items and their corresponding DataTemplates.

How to create an interactive Map using Images

I have a couple of images that I would like to create an interactive map of in Silverlight and WPF. The pictures are of States and counties. I tried doing some search on how this is done but have not been able to find a good example on how to go about accomplishing this. So I would appreciate your help. Thanks in advance.
I was involved in creating a Xaml World map from scratch (below) and that alone took nearly a day for a stylised polygon version (no fine detail)....
I have since purchased a Wacom Bamboo tablet & stylus and found that to be about 5 times faster to work with compared with a mouse.
Quoting myself: "You import a map as a background image and use the pen tool to dot-to-dot trace around the country. Combine all those path segments into a single path. Then create a separate poly-path for each state (close them to allow for a fill)."
Once you create them you can name the individual country polygons and connect up mouse logic to make them all glow on mouse over or change colour on press etc.
Basically all the other stuff on that screen are user controls and custom controls. Work out the behaviour you want and create controls to suit your own needs.
In your instance you can use less accurate polygons as they will only be for hit-testing and highlighting and you will want to retain the actual map images under the polygons.

How to draw lines between multiple Images

I need to visually show a line from one image to one or more images to represent a server connected to one or more servers. I'm assuming WPF is the best tool for this and am using this project to learn and evaluate WPF and determine if we should start migrating from WinForms.
I'm trying to keep the layout simple for purposes of re-sizing and managing the layout. So the image representing the source server is in the upper left and all connected servers are listed down the right side. I'm new to WPF and Expression Blend and have been struggling with how to draw the connectors. Right now I have the images in a grid. After some frustrating attempts to draw lines using tiled images I started to use a line with a GradientBrush which looks like a 2D pipe. This seemed like a decent approach. But I'm hoping there is an adequate method to draw a path similar to my mock up.
Thoughts...
Put the lines in the grid and span multiple rows and columns
Put the line on a canvas which spans all rows and columns
I assume the line paths will need to be determined in the code behind, But I've been impressed with everything XAML is capable of.
I'm just a WPF noob and a little overwhelmed by everything that WPF can do. This seems like something that's been done many times before but I cannot find any related WPF examples and would prefer to minimize my frustrating attempts :-)
I would use Canvas instead of Grid because you can use absolute positioning with Canvas.
Take a look at this 4 part series on CodeProject to get some ideas.
You can try using Seperator in between the images. Put seperator in a stackpanel so you can control its orientation to horizontal or vertical and you can also change its color and thickness. If you place seperator in a canvas you can also control its placement.

Categories