1

My problem is that the image that I am setting to my grid is not appearing, the only thing appearing is the black background, so I know the grid is working. I am a noob, and I am very confused. Thanks for the Help :)

Code:

    public partial class MainWindow : Window
    {
        static String ImgNameMole = "C:/Users/MonAmi/Desktop/mole2.png";

        public MainWindow()
        {
            InitializeComponent();
            GridMain();
        }

        private void GridMain()
        {
            Grid grid_Main = new Grid();
            MainWindow1.Content = grid_Main;
            grid_Main.Height = 350;
            grid_Main.Width = 525;

            grid_Main.Background = Brushes.GreenYellow;

            CreateImage();

        }

        private Image CreateImage()
        {
            Image Mole = new Image();
            Mole.Width = 25;
            Mole.Height = 25;
            ImageSource MoleImage = new BitmapImage(new Uri(ImgNameMole));
            Mole.Source = MoleImage;
            return Mole;
        }
    }
6
  • Where do you populate the grid? Commented May 24, 2013 at 19:27
  • @New Pin What do you mean? Commented May 24, 2013 at 19:27
  • You have created a CreateImage function but you are not using it anywhere. Commented May 24, 2013 at 19:28
  • Where do you define the content of the grid?; where do you fill it Commented May 24, 2013 at 19:29
  • Even if I put "CreateImage();" in the grid methid it still does not work Commented May 24, 2013 at 19:29

1 Answer 1

6

Nowhere in your code you are calling CreateImage(), so:

var img = CreateImage();
Grid.SetRow(img, 0);
Grid.SetColumn(img, 0);
grid_Main.Children.Add(img);

assuming that you have added at least one row and one column to your grid.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.