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.
I would implement that next way:
and
and
Edit: Data Context:
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.datacontext.aspx
This is how MSDN defines it: