Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8879097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:52:32+00:00 2026-06-14T19:52:32+00:00

I am attempting to render some Image objects in a canvas ( Layout )

  • 0

I am attempting to render some Image objects in a canvas (Layout) on the main form of my application which is called Main. I am using C# and WPF to create the application but am unable to get the images to render from within another class but works without problems in the Main form partial class.

public static void renderStarscape(int density = 200)
    {
        Main main = new Main();
        Random random = new Random();
        for (int x = 0; x < density; x++)
        {
            int starSize = random.Next(1, 10);
            int starOpacity = random.Next(10, 30);
            int starX = random.Next(0, 800);
            int starY = random.Next(0, 500);
            Image Star = new Image();
            Star.Name = (x < 10) ? "star_0" + x : "star_" + x;
            Star.Source = streamImage("star_background.png");
            Star.Height = starSize;
            Star.Width = starSize;
            Star.Opacity = (double)starOpacity / 100;
            main.Layout.Children.Add(Star);
            Canvas.SetLeft(Star, starX);
            Canvas.SetTop(Star, starY);
            Canvas.SetZIndex(Star, 0);
        }
    }

Any help would be great, thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:52:34+00:00Added an answer on June 14, 2026 at 7:52 pm

    You are creating an all new instance of Main in the method which is not same as the one shown on UI.

    Instead pass on the instance of the Canvas to the method and draw on that something like this –

    public static void renderStarscape( Canvas layout, int density = 200)
    {
        // Use layout and remove the Main object initialization from the method.
        layout.Children.Add(Star);
    }
    

    The reason its working in partial declaration of class is that you are using the same instance and not creating the new one for Main().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to render a textured quad using the example located here . I
I am attempting to render a UI using Sproutcore where I have a list
Some background: I am attempting to create a DirectShow source filter based on the
I'm attempting to render the following text using the ExtTextOut function with the Courier
I'm attempting to do some validation for user input using Express and Mongoose. Previously,
I've been attempting to render text onto an openGL window using SDL and the
I'm attempting to add some ajax to my pagination using the will_paginate gem as
I'm having some trouble pulling up relationed objects from my database using Doctrine2 in
I'm attempting to upload an image via ajax using paperclip. I'm using the qqfileuploader
I'm attempting to render xml from a service application. In the model, the relationship

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.