我有以下代码,其中有一个要绑定到DataGrid的DataTable。如果SelectedLot不为null,则将数据添加到DataTable中,并正确显示数据。但是,如果SelectedLot为null,我想显示其中包含“无”字符串的空白行。出于某种原因,当我调试它时,它明确表示其中有一行,但没有显示在DataGrid中。请帮忙。
DataTable的代码
(defn gen-frame [num-pixels]
(repeatedly num-pixels
#(->Pixel (rand-int 256) (rand-int 256) (rand-int 256) (rand-int 256))))
(defn frame-op [frame] ;; not very interesting for random pixels
(let [num-pixels (count frame)
avg #(double (/ (apply + (map % frame)) num-pixels))]
(->Pixel (avg :r) (avg :g) (avg :b) (avg :a))))
(time
(->> (repeatedly #(gen-frame (* 1920 1080)))
(map frame-op)
(take 60)
(doall)))
"Elapsed time: 240527.803662 msecs"
=>
(#sandbox.core.Pixel{:r 127.4540152391975, :g 127.4542722800926, :b 127.3754962384259, :a 127.4886294367284}
#sandbox.core.Pixel{:r 127.4727488425926, :g 127.4447955246914, :b 127.4472164351852, :a 127.4626080246914}
...
Xaml
public void PopulateLotDataTable(PlateSetupViewModelEx2 plateViewModel)
{
try
{
if (LotInformationDataTable == null)
{
LotInformationDataTable = new DataTable();
}
LotInformationDataTable.Columns.Add(WinApp.Current.TryFindResource("LotType").ToString());
LotInformationDataTable.Columns.Add(WinApp.Current.TryFindResource("CatalogNumber").ToString());
LotInformationDataTable.Columns.Add(WinApp.Current.TryFindResource("SupermixColumnHeader").ToString());
LotInformationDataTable.Columns.Add(WinApp.Current.TryFindResource("LotNumber").ToString(), typeof(string));
DataRow dr = null;
var SelectedLot = plateViewModel.PlateSetupToUse.GetAllWellSamples().Values.FirstOrDefault(x => x.SelectedLots != null);
if (SelectedLot != null)
{
foreach (var item in SelectedLot?.SelectedLots)
{
foreach (var subitem in item?.KitLots)
{
dr = LotInformationDataTable.NewRow();
dr[0] = EnumExtensions.ToDescriptionString(item.KitLotType);
dr[1] = subitem.CatalogNumber;
dr[2] = subitem.Supermix;
dr[3] = subitem.LotNumber;
LotInformationDataTable.Rows.Add(dr);
}
}
}
else
{
dr = LotInformationDataTable.NewRow();
LotInformationDataTable.Rows.Add(dr);
for (int i = 0; i < LotInformationDataTable.Columns.Count; i++)
{
LotInformationDataTable.Rows[0][i] = WinApp.Current.TryFindResource("None").ToString(); //This is not working I guess.
}
Debug.Write(LotInformationDataTable.Rows.Count);
}
}
catch(Exception ex)
{
SystemDebugLogLogger.LogException(ex);
}
}
答案 0 :(得分:0)
在else
部分尝试:
dr = LotInformationDataTable.NewRow();
// First add data in empty row
for ( int i = 0; i < LotInformationDataTable.Columns.Count; i++ )
{
dr[i] = WinApp.Current.TryFindResource( "None" ).ToString();
}
// Notify UI by adding row in collection.
LotInformationDataTable.Rows.Add( dr );
Debug.Write( LotInformationDataTable.Rows.Count );
我猜在您在DataGrid
中添加行之后添加数据时,DataSource
的{{1}}没有得到通知