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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:11:38+00:00 2026-05-20T17:11:38+00:00

I am new to WPF. A class property that has array of names (reading

  • 0

I am new to WPF.

A class property that has array of names (reading from appconfig)

class Sample
{
    private string[] names; 
    public string[] Names
    {
        get
        {
        names = ConfigurationManager.AppSettings["UserNames"].Split(',');
            return machines;
        }
        set { names = value; }
    }
}

I want to populate a WPF Gridview with these names.

Here is my NamesView.xaml:

 <ListView>
        <ListView.View>
            <GridView AllowsColumnReorder="True" >
                <GridViewColumn Header="Names" Width="auto" DisplayMemberBinding="{Binding Path=Names}"/>
            </GridView>
        </ListView.View>
 </ListView>

Here is my code behind NamesView.xaml.cs:

public partial class ServerView : Windows
{
    public ServerView()
    {
        InitializeComponent();
        Sample sample = new Sample();
        this.DataContext = sample.Names;
    }
}

Question:

Not able to understand what is mistake? If any site or stuff is there to study, please share?

[Solved]

Actually for grid view DataContext is not working, I used Itemssource and it worked.

  • 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-20T17:11:39+00:00Added an answer on May 20, 2026 at 5:11 pm

    I would implement that next way:

    public class Person
    {
        public string Name { get; set; }
    
        public List<Person> GetAll()
        {
            List<Person> names = new List<Person>;
            string[] namesArray = ConfigurationManager.AppSettings["UserNames"].Split(',');
            foreach(var name in namesArray)
            {
                names.Add(new Person { Name = name });
            }
            return names;
        }
    }
    

    and

    <GridView Name="MyGridView" AllowsColumnReorder="True" >
        <GridViewColumn Header="Names" Width="auto" DisplayMemberBinding="{Binding Path=Name}" />
    </GridView>
    

    and

    public void Page_Load(object sender, EventArgs e)
    {
        InitializeComponent();
        Person all = new Person();
        MyGridView.DataSource = all.GetAll();
    }
    

    Edit: Data Context:
    http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontext.aspx

    This is how MSDN defines it:

    Data context is a concept that allows
    elements to inherit information from
    their parent elements about the data
    source that is used for binding, as
    well as other characteristics of the
    binding, such as the path.

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

Sidebar

Related Questions

I am new to WPF. I have a ListBox that has its ItemSource set
I have a very simple class that has a single property and which inherits
In my new WPF Application, I am reusing a Model class. In that model
I am new to WPF so after reading for a while I deduce that
I have the following class Person: public class Person { public string Name {
I am (very) new to WPF and I have got a question regarding that.
I am relatively new to WPF and would like to create a UserControl that
WPF control-derived class has a composition of non-WPF control-derived class . The latter class,
I have the following ValidationRule class in WPF public class EmptyFieldValidationRule: BaseValidationRule { public
I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();

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.