Reputation: 233
i have two Windows. In Windows 1 i prepare an ObservableCollection. In Windows 2 i want bind this to a listview.
They are both in the same namespace.
public partial class Window1 : Window
{
public ObservableCollection<KeyListItem> keys;
public Window1 {
this.keys = new ObservableCollection<KeyListItem>();
... some code i create the items (key) ...
keys.Add(key);
}
private void OpenDialogAndShowList() {
//this i start from a button
var sKeys = new Window2();
sKeys.lvSelectKey.ItemsSource = keys;
}
}
In Window2 the XAML looks like this:
<Grid>
<ListView Name="lvSelectKey" ItemsSource="{Binding keys}" HorizontalAlignment="Left" Height="211" Margin="10,10,0,0" VerticalAlignment="Top" Width="564">
<ListView.View>
<GridView>
<GridViewColumn Width="140" Header="Id" DisplayMemberBinding="{Binding Path=Id}" />
<GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Width="140" Header="Algorithm" DisplayMemberBinding="{Binding Path=Algorithm}" />
<GridViewColumn Width="140" Header="Bits" DisplayMemberBinding="{Binding Path=Bits}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
The Problem is:
i see some empty lines in my listview. When i add three items, i see three lines ..... and so on.
But i don`t see any content.
When i debug it, i see the OC is not empty.
Somebody see my failure? :)
Upvotes: 0
Views: 49
Reputation: 7304
You should adjust the class as follows:
public class KeyListItem
{
public int Id { get; set; }
public string Name { get; set; }
public string Algorithm { get; set; }
public int Bits { get; set; }
}
That is use properties instead of simple fields: the binding engine works only on properties.
Upvotes: 1
Reputation: 233
I got it, thank you Mario. I forgot the get; set;
public class KeyListItem
{
public int Id { get; set;}
public string Name { get; set; }
public string Algorithm { get; set; }
public int Bits { get; set; }
}
Upvotes: 0