DataView
DataView represents a control that displays scalar and DataSet data, as shown in AdventureWorksLT.WpfApp
sample:
Features
DataView acts as root UI container for scalar and DataSet data presentation. In addition, it implements the following command handlers:
- Asynchronously data loading state.
- Scalar data editing.
- Delete selected row(s).
- Clipboard copy/paste.
Usage
Typically, DataView is added to your XAML UI, then call Show method of your presenter class to show data to the this view.
You can also add DataView as row binding via BindToDataView, to display child DataSet as sub DataView.
Implemented Commands
Command | Input | Implementation |
---|---|---|
CancelDataLoad | Control template | Cancels data loading. |
RetryDataLoad | Control template | Retries data loading. |
ToggleEditScalars | Toggles scalar editing mode. | |
BeginEditScalars | Begins scalar editing mode. | |
EndEditScalars | Ends scalar editing mode. | |
CancelEditScalars | Cancels scalar editing mode. | |
Delete | Same as ApplicationCommands.Delete | Deletes selected row(s). |
Copy | Same as ApplicationCommands.Copy | Copies selected row(s) to clipboard. |
PasteAppend | Same as ApplicationCommands.Paste | Pastes append data from clipboard. |
Customizable Services
- DataView.ICommandService: Your data presenter can implement this service to change the commands implementation of this class.
- DataView.IPasteAppendService: Your data presenter can implement this interface to verify data to be pasted, for example, retrieve lookup data for foreign key, as demonstrated in
AdventureWorksLT.WpfApp
sample:
bool DataView.IPasteAppendService.Verify(IReadOnlyList<ColumnValueBag> data)
{
var foreignKeys = DataSet<Product.Ref>.Create();
for (int i = 0; i < data.Count; i++)
{
var valueBag = data[i];
var productId = valueBag.ContainsKey(_.ProductID) ? valueBag[_.ProductID] : null;
foreignKeys.AddRow((_, dataRow) =>
{
_.ProductID.SetValue(dataRow, productId);
});
}
if (!App.Execute((db, ct) => db.LookupAsync(foreignKeys, ct), Window.GetWindow(View), out var lookup))
return false;
Debug.Assert(lookup.Count == data.Count);
var product = _.Product;
for (int i = 0; i < lookup.Count; i++)
{
data[i].SetValue(product.Name, lookup._.Name[i]);
data[i].SetValue(product.ProductNumber, lookup._.ProductNumber[i]);
}
return true;
}