I've got a ListView control bound to an ObservableCollection of items, and I've set it's view to a GridView with columns bound to properties Data. Things seem to be ok, but the data in the source properties aren't being rendered at all. Here's the ScanData struct:
struct ScanData
{
public ushort Port;
public bool? Status;
public string ServiceName;
}
The XAML:
<ListView IsSynchronizedWithCurrentItem="True" Width="Auto" Name="_resultsListView" ItemsSource="{Binding}" Height="138">
<ListView.View>
<GridView ScrollViewer.IsDeferredScrollingEnabled="True">
<GridViewColumn Header="Port" Width="50" DisplayMemberBinding="{Binding Path=Port}"/>
<GridViewColumn Header="Status" DisplayMemberBinding="{Binding Path=Status}"/>
<GridViewColumn Header="Service" Width="231" DisplayMemberBinding="{Binding Path=ServiceName}"/>
</GridView>
</ListView.View>
</ListView>
The codebehind (the most relevant parts, anyway):
public partial class AddServerDialog
{
PortScanner _scanner;
ObservableCollection<ScanData> _resultList;
Brush _defaultPortTextBorderBrush;
public AddServerDialog()
{
this.InitializeComponent();
_resultList = new ObservableCollection<ScanData>();
_resultsListView.DataContext = _resultList;
}
// ...
private void _addScanButton_Click(object sender, RoutedEventArgs e)
{
_resultList.Add(_scanner.CreateScan(ushort.Parse(_portText.Text)));
}
}
When I click the button that causes _addScanButton_Click to fire, I can see that items get added tot he rendered ListView (e.g., rows are selectable), but the three columns show nothing in them. The ScanData items in the DataContext all have their Port property set, so shouldn't it be rendering numbers in the "Port" column? The other two properties are null at runtime and so I don't expect to see them.