I have below bound RadGridView and I am trying to export its contents, but it always results into an empty exported file.
我有下面的RadGridView绑定,我试图导出其内容,但它总是导致一个空的导出文件。
<telerik:RadGridView Grid.Row="0" x:Name="Logs"
SelectedItem="{Binding SelectedLogEntry, Mode=TwoWay}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn CellTemplateSelector="{StaticResource IconTemplateSelector}" IsResizable="False"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding LogLevel,Mode=OneWay}" Header="Level"
CellStyle="{StaticResource PaddedCell}" MinWidth="50">
</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn DataMemberBinding="{Binding LogID,Mode=OneWay}" Header="LogID"
SortMemberPath="LogID" SortingState="Descending" MinWidth="50"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding MachineDateTime,Mode=OneWay}"
Header="Machine Time" CellStyle="{StaticResource PaddedCell}" MinWidth="150"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Occured, Mode=OneWay}" Header="Occured" MinWidth="100" CellStyleSelector="{StaticResource ColorSelector}"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding System,Mode=OneWay}" Header="System" MinWidth="50"
CellStyle="{StaticResource PaddedCell}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Mode,Mode=OneWay}" Header="Mode" MinWidth="50"
CellStyle="{StaticResource PaddedCell}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding CallingClass,Mode=OneWay}"
Header="Calling Class" MinWidth="250" Width="Auto"
CellStyle="{StaticResource PaddedCell}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Message,Mode=OneWay}" Header="Message"
Width="250" CellStyle="{StaticResource PaddedCell}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Exception,Mode=OneWay}" Header="Exception" Width="350" CellStyle="{StaticResource PaddedCell}" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
The method to export logs:
导出日志的方法:
private void ExportLogs()
{
using (var stream = File.Create(filepath))
{
Logs.Export(stream,
new GridViewExportOptions()
{
Format = ExportFormat.ExcelML,
ShowColumnHeaders = true,
ShowColumnFooters = false,
ShowGroupFooters = false,
});
}
}
No exceptions or warning received. Any help would be appreciated. Thank you.
没有收到任何例外或警告。任何帮助,将不胜感激。谢谢。
1 个解决方案
#1
0
The problem with my code was that due to multiple threads, the GridView was accessed from a non-UI thread, which lead contents of GridView to be in inaccessible state. So I tried to call the Export function from the UI thread and it worked as expected.
我的代码的问题是,由于多个线程,GridView是从非UI线程访问的,这导致GridView的内容处于无法访问状态。所以我尝试从UI线程调用Export函数,它按预期工作。
#1
0
The problem with my code was that due to multiple threads, the GridView was accessed from a non-UI thread, which lead contents of GridView to be in inaccessible state. So I tried to call the Export function from the UI thread and it worked as expected.
我的代码的问题是,由于多个线程,GridView是从非UI线程访问的,这导致GridView的内容处于无法访问状态。所以我尝试从UI线程调用Export函数,它按预期工作。