controls ( button and image)

Oct 16 2013 7:05 AM
how can i generate the images randomly by clicking the button ?,
i used button control and placed the image controller on the button . I'm unable to generate the images randomly , please help me  how can i do .....

i try by this code , but i can generate only one image at one click. if try to click the button it is not generating the other images.... 

private void button1_Click_1(object sender, RoutedEventArgs e)
        {
            Random r = new Random();
            int d = r.Next(1,7);
            textBlock1.Text = d.ToString();

            switch (d)
            {
                case 1:
                    myimage.Source = new BitmapImage(new Uri(@"/imagedice;component/Images/dice1.png", UriKind.Relative));
                    break;

                case 2:
                    myimage.Source = new BitmapImage(new Uri(@"/imagedice;component/Images/dice2.png", UriKind.Relative));
                    break;

                case 3:
                    myimage.Source = new BitmapImage(new Uri(@"/imagedice;component/Images/dice3.png", UriKind.Relative));
                    break;

                case 4:
                    myimage.Source = new BitmapImage(new Uri(@"/imagedice;component/Images/dice4.png", UriKind.Relative));
                    break;

                case 5:
                    myimage.Source = new BitmapImage(new Uri(@"/imagedice;component/Images/dice5.png", UriKind.Relative));
                    break;

                case 6:
                    myimage.Source = new BitmapImage(new Uri(@"/imagedice;component/Images/dice6.png", UriKind.Relative));
                    break;
            }
           
           

        }

Answers (1)