Exercise: Create styles/resources to generate a playing card

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!

Category ==> WPF - Visual C#  (20 exercises)
Topic ==> Resources  (3 exercises)
Level ==> Harder than average
Course ==> WPF using Visual C#

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Create a new window called Diamond.  The aim of this exercise is to create a playing card, where the number and size of symbol can vary:

Small Ace of Diamonds Jack of diamonds, bigger
50% scaling of Ace 200% scaling of Jack

First create two window-level resources as follows:

  • a String data type resource called CardSymbol, initially set to A; and
  • a Double data type resource called SymbolReduction, initially set to 0.5.

Don't forget to reference the mscorlib namespace in your window, so the data types can work.

Now create a StackPanel within a Border (whose CornerRadius is set to 10, to produce the rounded corners), and put in this:

  • a label whose content should equal the CardSymbol resource value; and
  • a polygon with Points property equal to something like "20,0 0,20 20,40 40,20", and a ScaleTansform with ScaleX property set to the value of the SymbolReduction resource.

Try amending the resource values in your XAML, and check that you get different results as you would expect.

If you still have time, try combining styles and resources to get the core XAML of your window to be as clean as possible:

Clean XAML for window

This is what the answer looks like!

 

Close any windows you have open.

This page has 0 threads Add post