2012-02-07 5 views
1

イメージでボタンをプログラムで作成する方法を教えてください。私は、カードゲーム内のすべての可能なカードを表すメモリ内の画像とともにボタンを保存したい。次に、私がプレイヤーに配られたカードを表示するとき、私はすべての可能なカードの配列から正しいカードを選択することができます。イメージ付きWindows Phone 7のボタン

Button[] cardButtons = new Button[52]; 
for(int i = 0; i < 52; i++) 
{ 
    cardButtons[i] = new Button(); 
    cardButtons[i] = new Image(.... I dont know what goes here, or if any of this is correct!) 
} 

正しいトラックにはありますか?

ありがとうございます。

答えて

3

Buttonクラスの.Contentプロパティを使用できます。

Button[] cardButtons = new Button[52]; 
for(int i = 0; i < 52; i++) 
{ 
    Uri uri = new Uri("/images/someImage.png", UriKind.Relative); 
    BitmapImage imgSource = new BitmapImage(uri); 
    Image image = new Image(); 
    image.Source = imgSource; 
    cardButtons [i] = new Button(); 
    cardButtons[i].Content = image; 
}