WPF DataGrid:Binding&水平视图&自动生成列 [英] WPF DataGrid: Binding & Horizontal View & Autogenerate columns

查看:98
本文介绍了WPF DataGrid:Binding&水平视图&自动生成列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从XML文件中获取特定的DataGrid:



I'm trying to get a specific DataGrid from an XML file:

          | 01/01/2015 | 02/01/2015 | 03/01/2015
Value 1   |   0.00025  | 0.0000026  |    0.01
.         |..
.         |..
Value n   |..
Average   |..
Expanse   |..





我的Xml文档是:



My Xml document is:

<?xml version="1.0" encoding="utf-8"?>
<data>
	<cote>
		<name>XXX</name>
		<filescount>5</filescount>
		<comments>XXX</comments>
		<averageinf>-0.01</averageinf>
		<averagesup>0.01</averagesup>
		<expansemax>0.05</expansemax>
		<control>
			<date>07/08/2014</date>
			<values>
				<value>-0.001</value>
				<value>0.017</value>
				<value>0.034</value>
				<value>0.022</value>
				<value>0.021</value>
			</values>
			<average>0.0186</average>
			<expanse>0.035</expanse>
		</control>
		<control>
			<date>07/08/2014</date>
			<values>
				<value>0.002</value>
				<value>0.001</value>
				<value>0</value>
				<value>0.001</value>
				<value>0</value>
			</values>
			<average>0.0008</average>
			<expanse>0.002</expanse>
		</control>
	</cote>
</data>





对于每个控件,我想要一个列有他的d ata。



我尝试了很多东西,翻转datagrid(使用布局转换)但没有成功,有一些数据在重新绘制窗口时不会出现,手动添加列,但我无法手动添加行...



请问您有解决方案吗?



谢谢并原谅我的英语

Zwormi



For each "control", i want to have a column with his data.

I tried a lot of things, flip datagrid (with layout transform) but without success, there are some datas which not appear when repainting window, add columns manually, but i cannot add rows manually...

Do you have a solution please?

Thanks and Excuse my English
Zwormi

推荐答案

只是一个快速的建议(我不明白你的尝试,或试图告诉 - 丢失在翻译中?):



将XML读入数据的内部表示。



例如这样的事情



Only a quick suggestion (I don't understand what you tried, or trying to tell - lost in translation?):

Read in your XML to a internal representation of your data.

e.g. something like this

class Control
{
    public DateTime Date { get; set; }
    public double[] Values { get; set; }
    public double Avarage { get; set; }
    public double Expanse { get; set; }
}





...将实例添加到列表中





...add the instances to a list

List<control> listControls;</control>





...将它们绑定到您的数据网格





...bind them to your datagrid

datagrid.ItemsSource = listControls;


这篇关于WPF DataGrid:Binding&amp;水平视图&amp;自动生成列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆