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 447689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:35:43+00:00 2026-05-12T21:35:43+00:00

I want a attribute in my Hero class to have a Portrait attribute for

  • 0

I want a attribute in my Hero class to have a Portrait attribute for his/her image. What object type should I use in this case?

public class Hero
{
    public string Name { get; set; }
    public string HeroType { get; set; }
    public int StartingHP { get; set; }
    public int StartingMana { get; set; }
    public Dictionary<string, string> Spells { get; set; }
    public Dictionary<string, string> Items { get; set; }        
}
  • 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-05-12T21:35:43+00:00Added an answer on May 12, 2026 at 9:35 pm

    In WPF, you should use the ImageSource class, like this:

    public class Hero {
        public string Name { get; set; }
        public string HeroType { get; set; }
        public int StartingHP { get; set; }
        public int StartingMana { get; set; }
        public Dictionary<string, string> Spells { get; set; }
        public Dictionary<string, string> Items { get; set; } 
        public ImageSource Portrait { get; set; }
    }
    

    You can read an image from a file like this:

    myHero.Portrait = new BitmapImage(new Uri(filePath, UriKind.Absolute));
    

    You can use the Image class from System.Drawing.dll. For example:

    public class Hero {
        public string Name { get; set; }
        public string HeroType { get; set; }
        public int StartingHP { get; set; }
        public int StartingMana { get; set; }
        public Dictionary<string, string> Spells { get; set; }
        public Dictionary<string, string> Items { get; set; } 
        public Image Portrait { get; set; }
    }
    

    To load the image, call Image.FromFile(path). If you have an image in a stream (eg, from a database or web service, you can call Image.FromStream(stream).

    If you have all of the images at compile time, you can put them in a ResX file; you can get an image from the designer-generated code file like this: myHero.Portrait = SomeResXFile.Portrait1.

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

Sidebar

Related Questions

I want to assign a class attribute via a string object - but how?
I want to alter the class attribute of an image tag in PHP. I
I want to specify an argument in an attribute, like this: [OutputCache(Duration = GlobalSettings.GlobalVar)]
I know I could have an attribute but that's more work than I want
My Invoice model has an address_id attribute, and I don't want this address_id to
I'm trying to force an inherited class to use a custom attribute. I'm creating
I want to use a temp directory that will be unique to this build.
If you want to create a custom attribute for MS test (say [Repeat(3)] how
I want to list (a sorted list) all my entries from an attribute called
I want to set some attributes just before the object is serialized, but as

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.