我有一个UWP应用,正在使用RadDataGrid显示一些数据。当我对API进行API调用以在网格中设置数据时,数据网格显示为空行。
我的XAML
<tg:RadDataGrid Grid.Row="2" UserGroupMode="Disabled" ColumnDataOperationsMode="Flyout" x:Name="infoGrid" ItemsSource="{x:Bind Path=ViewModel.history}" AutoGenerateColumns="False" FontSize="24" VerticalContentAlignment="Top" Margin="0,0,0,50" VerticalAlignment="Top" MaxHeight="500">
<tg:RadDataGrid.Columns>
<tg:DataGridTextColumn PropertyName="UpdatedBy" Header="Verplaatst door"/>
<tg:DataGridDateColumn PropertyName="UpdateDate" Header="Bijgewerkt op" CellContentFormat=" {0:dd/MM/yyyy}" />
<tg:DataGridTextColumn PropertyName="Location" Header="Verplaatst naar"/>
</tg:RadDataGrid.Columns>
</tg:RadDataGrid>
我的C#代码来设置数据
public async void APICALL()
{
var result = await LotService.GetLotInfo(ViewModel.scanField);
ViewModel.lot = result;
ViewModel.history = result.LotHistory;
infoGrid.ItemsSource = null;
infoGrid.ItemsSource = ViewModel.history;
IsBusy = false;
}
}
ViewModel.history是LotHistoryInfo类的列表
编辑:建议将吸气剂和吸气剂添加为mm8
public class LotHistoryInfo
{
public LotInfo lot { get; set; }
public string scanField { get; set; }
public List<LotHistoryInfo> history { get; set; }
public LotHistoryInfo(LotStoreHistory his)
{
Location = new Location(his.LshStoreid.ToString(), his.LshStorex, his.LshStorey, his.LshStorez);
UpdatedBy = his.UpdatedBy;
UpdateDate = his.Updated;
}
public LotHistoryInfo()
{
}
}
那么,我想念什么?
答案 0 :(得分:2)
您只能绑定到公共属性:
public class LotHistoryInfo
{
public Location Location { get; set; }
public string UpdatedBy { get; set; }
public DateTimeOffset UpdateDate { get; set; }
public LotHistoryInfo(LotStoreHistory his)
{
Location = new Location(his.LshStoreid.ToString(), his.LshStorex, his.LshStorey, his.LshStorez);
UpdatedBy = his.UpdatedBy;
UpdateDate = his.Updated;
}
public LotHistoryInfo()
{
}
}
您已将Location
,UpdatedBy
和UpdateDate
实现为字段:
public Location Location;
public string UpdatedBy;
public DateTimeOffset UpdateDate;