Reputation: 5469
I've got simple class
public class Person
{
string Name { get; set; }
string Path { get; set; }
}
I've got also System.Windows.Controls.ListView containing several this type objects.
I'd like to show both properties (or more if it will be) in this ListView.
If I have one I know I can do this using DisplayMemberPath:
<ListView DisplayMemberPath="Name" Name="listViewClients" />
But how can I get result like this:
"Name: Path"
(I mean of course values of this properties for appropiate object)
Upvotes: 1
Views: 2555
Reputation: 852
You could also override the ToString()
method and omit setting DisplayMemberPath
, which might be more elegant in some cases:
public class Person
{
string Name { get; set; }
string Path { get; set; }
public override string ToString()
{
return Name + ": " + Path;
}
}
Upvotes: 3
Reputation: 39006
One way to do this is, create another readonly property to wrap them up.
string NamePath { get { return Name + ": " + Path; }}
then you can just set the DisplayMemberPath to NamePath
Upvotes: 4