Can you tell me how to associate a WPF DataGrid with an ObservableCollection. I saw several posts and did not find a direct answer. Complex problems are described there and everywhere, but my problem is rather not complicated. I have an observable collection and a WPF DataGrid. Both are in the WPF application, which is a duplex contract WCF service client. Here is the ObservableCollection:
private ObservableCollection<MyClass> _myCollection = new ObservableCollection<MyClass>();
public ObservableCollection<MyClass> DownloadsCollection
{
get { return this._downloadsCollection; }
}
Here is the XAML markup with a DataGrid:
<Window x:Class="DownloadManager_Client.MainWindow"
. . . . . . . .>
<DataGrid Name="dgDownloadsInfo" Grid.Row="2" Grid.Column="0" AutoGenerateColumns="False" CanUserAddRows="False"
CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeColumns="False"
CanUserResizeRows="False" CanUserSortColumns="False" SelectionMode="Single" SelectionChanged="dgDownloadsInfo_SelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="DownloadId" Visibility="Hidden"/>
<DataGridTextColumn Header="Target URL" FontFamily="Arial" />
<DataGridTextColumn Header="Content Size" FontFamily="Arial"/>
<DataGridTextColumn Header="Path to Save" FontFamily="Arial"/>
<DataGridTextColumn Header="Bytes Downloaded" FontFamily="Arial"/>
<DataGridTextColumn Header="Percent (%)" FontFamily="Arial"/>
<DataGridTextColumn Header="Status" FontFamily="Arial"/>
</DataGrid.Columns>
</DataGrid>
. . . . . . . .
</Window>
And here is the myClass class. It is implemented in the WCF service. The client receives instances of MyClass in callbacks from a WCF service with a two-way contract. After each instance of MyClass has been received, it is placed in the ObservableCollection to replace the previous one with the same unique identifier.
[DataContract]
public class MyClass
{
#region Properties
[DataMember]
public Guid UniqueId { get; set; }
[DataMember]
public String TargetUrl { get; set; }
[DataMember]
public String PathToSave { get; set; }
[DataMember]
public Int32 Percentage { get; set; }
[DataMember]
public Int64 DownloadedBytesQuantity { get; set; }
[DataMember]
public Int64 RealContentLength { get; set; }
[DataMember]
public String Status { get; set; }
#endregion
}
DataGrid ObservableCollection ? . .