C# 如何从数据网格中以特定格式创建txt文件?

C# 如何从数据网格中以特定格式创建txt文件?,c#,wpf,text,format,save,C#,Wpf,Text,Format,Save,我是编程新手。我目前正在使用C#中的WPF将XML文件中的数据生成到数据网格(表)中。我使用的是MVVM格式。对于我的模型类,我将其命名为PersonInfo,它包括“名字”、“姓氏”、“选择”和“年龄”列。我想通过单击“选择”列中的复选框,根据用户选择的行创建一个txt文件。txt文件的格式如下所示: e.g. P§Alexander§Jason§24§ P§ = It is the keyword for PersonInfos Alexander§ = Last Name Jason§

我是编程新手。我目前正在使用C#中的WPF将XML文件中的数据生成到数据网格(表)中。我使用的是MVVM格式。对于我的模型类,我将其命名为PersonInfo,它包括“名字”、“姓氏”、“选择”和“年龄”列。我想通过单击“选择”列中的复选框,根据用户选择的行创建一个txt文件。txt文件的格式如下所示:

e.g.
P§Alexander§Jason§24§

P§ = It is the keyword for PersonInfos
Alexander§ = Last Name
Jason§ = First Name
24§ = Age
我将在下面的xaml中显示我的WPF代码,以提供更好的想法

<syncfusion:GridTreeControl.Columns>
                <syncfusion:GridTreeColumn MappingName="LastName" PercentWidth="3" /> 
                <syncfusion:GridTreeColumn MappingName="FirstName" PercentWidth="3" /> 
                <syncfusion:GridTreeColumn MappingName="Age" PercentWidth="2" /> 
                <syncfusion:GridTreeColumn MappingName="Select" PercentWidth="2">
                    <syncfusion:GridTreeColumn.StyleInfo>
                        <syncfusion:GridDataStyleInfo
                                CellType="DataBoundTemplate"
                                CellItemTemplate="{StaticResource SelectCheckBoxTemplate}"/>
                    </syncfusion:GridTreeColumn.StyleInfo>
                </syncfusion:GridTreeColumn>            
</syncfusion:GridTreeControl.Columns>


谢谢你抽出时间

最简单的方法是将属性bool IncludeInExport添加到模型类(或派生模型类或偏于模型类的类)并将其映射到网格的复选框。在导出中,您将添加刚刚选中的行(IncludeInExport==true的PersonInfo集合项)