ItemsSource ListView is a collection whose items will be displayed in the list. So think about what you are asking for a ListView:
- As the source set, use something that is not a collection but contains them
- For each row in the list, displays an item from one collection and an item from another collection
Pay attention to this second point: each line should display some element from the Events collection and some element from the description collection.
Which item to choose from each? What is the relationship between the elements in the two collections?
It looks like you really need a collection of objects containing both the event and the description. Then you can bind this collection to display elements of both objects. Like that:
public class EffectView : INotifyPropertyChanged { ObservableCollection<EffectsAndDescriptions> effects; public ObservableCollection<EffectAndDescriptions> Effects { get { return this.effects; } set { this.effects = value; this.RaisePropertyChanged ( "EffectsAndDescriptions" ); } } } internal class EffectsAndDescriptions { public Effect Effect { get; set; } public Description Description { get; set; } }
Now you can bind to the EffectsAndDescriptions collection (note that it is assumed that the DataContext of the ListView EffectView )
<ListView ItemsSource="{Binding EffectsAndDescriptions}"> <ListView.View> <GridView> <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Effect.Name}" Header="Name" /> <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Effect.Opacity}" Header="Opacity" /> <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Description.Usage}" Header="Description" /> </GridView> </ListView.View> </ListView>
Dan j
source share