我在WPF PRISM项目中有用户控件,从按钮单击按钮(命令绑定)后面调用函数:
private async void UpdateStoreSet()
{
List<ValidationData> failedData = await _adapter.UpdateStoreSetData(this.DataList.Result as List<StoreSetData>);
if (failedData != null && failedData.Count > 0)
{
FailedValidationViewModel objFaliedVM = new FailedValidationViewModel(_errorHandler, _dlgService, failedData);
//objFaliedVM.DataList = failedData;
Windows.FailedValidation win = new Windows.FailedValidation(objFaliedVM, _errorHandler);
win.Owner = System.Windows.Application.Current.MainWindow;
win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
win.ShowDialog();
//_dlgService.ShowMessageBox(failedData.Count.ToString() + " records failed validation!", "Failure", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
// Refresh the list
SearchPlanograms();
}
}
在构造函数Window View Model中,这里写着:
public FailedValidationViewModel(IErrorHandlerService inErrorHandler, IDialogService inDlgService, List<ValidationData> lstFailedList)
{
// Set dependency injected services to local variables
_errorHandler = inErrorHandler;
_dlgService = inDlgService;
//Instantiate the failed validation list
DataList = lstFailedList;
// Instantiate the command
this.ExportToExcelCommand = new DelegateCommand<object>(this.ExportToExcel);
}
#endregion
#region Properties
public List<ValidationData> DataList
{
get
{
return _failedValidation;
}
set
{
if (_failedValidation != value)
{
SetProperty(ref _failedValidation, value);
}
}
}
#endregion
以下网格显示在窗口中:
<dxg:GridControl x:Name="gridFailedFloorplans" Grid.Row="0" AutoGenerateColumns="None"
ItemsSource="{Binding DataList.Result.View}" AutoExpandAllGroups="True" DefaultSorting="Name"
dx:ThemeManager.Theme="Default" Height="350" Width="580">
<dxg:GridControl.View>
<dxg:TableView AllowGrouping="True" ShowGroupPanel="False" AllowEditing="False" AutoWidth="True" Name="gridFailedValidationTableView"/>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="abc" />
<dxg:GridColumn FieldName="def" />
<dxg:GridColumn FieldName="efg" />
<dxg:GridColumn FieldName="ghi" />
<dxg:GridColumn FieldName="jkl FixedWidth="True" Width="100" />
<dxg:GridColumn FieldName="mmm" FixedWidth="True" Width="100" />
</dxg:GridControl.Columns>
</dxg:GridControl>
但是,如果ItemsSource = null,则网格将显示为空。我不知道如何解决它。请帮忙。
答案 0 :(得分:0)
不应该绑定
<dxg:GridControl ....
ItemsSource="{Binding DataList}"
否则它的&#39;在Result
上寻找属性List<ValidationData>
,该属性不存在并导致空itemsSource
。