Question

I am making a card game using expression blend. i will treat every card as a Button. In my code i will have a Card class. Now each card has a different look but they all behave the same as in movements and other actions. I am wondering if there is a way to use each card image (PNG) and set it as i initialize an instance of the Card class. The class will have the image path within it. It's like if i have a Card template and when i initialize one i give it the specific image to load. Thanks a lot

Was it helpful?

Solution

Use an ImageBrush and bind it to the ImageUrl (or whatever it is named) property of the Card class:

<Button>
  <Button.Background>
    <ImageBrush ImageSource="{Binding ImageUrl}" />
  </Button.Background>
</Button>

Your Card class would be something like this:

class Card{
   public string ImageUrl {get; set;}

   // other properties and stuff
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top