I like to declare images as resources in my XAML. I assume that you can still play with the code structure at the moment, and I hope there are not many new concepts for you. Here is how I do it:
Launch y by creating a folder in your project called Images. Add images of your cards by dragging them to a folder in Visual Studio. Make sure Build Action is set to Resource.
Create a new “resource dictionary” by pressing CTRL-SHIFT-A. Name it CardImages.xaml.
Link this file in App.xaml like this (it’s shown how to link several XAML files at once, but for this, of course, delete the line “AnyDictionary”!)
app.xaml:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Controls/CardImages.xaml" /> <ResourceDictionary Source="Controls/AnyDictionaryYouWant.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
Add this code to CardImages.xaml. Rename "MyBlackJackAssembly" to the name of your project assembly.
<Style TargetType="Image"> <Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality" /> </Style> <DataTemplate x:Key="Spade1"> <Image Source="MyBlackJackAssembly;component/Images/Spade1.png" /> </DataTemplate> <DataTemplate x:Key="Spade2"> <Image Source="MyBlackJackAssembly;component/Images/Spade2.png" /> </DataTemplate>
Then you can find them in your code as follows:
Label label = new Label(); label.ContentTemplate = (DataTemplate)label.FindResource("Spade1");
This will give you a WPF Label object that should show your map. This method works with everything that supports the ContentTemplate. Then you can add your shortcut to the grid of your user interface, I'm not sure how you display your maps on the screen.
For a blackjack application, I probably create a UserControl called "Card" to be able to generate it sort of. This encapsulates the map-forming logic into its own control, so the rest of the code can simply focus on working with cards.
XAML:
<myControls:CardImage Kind="Spades" Digit="1" />
Or as in C #:
CardImage aCard = new CardImage(); aCard.Kind = CardImage.Kinds.Spades;