与DataGrid中的WPF应用程序处理应用程序、DataGrid、WPF

2023-09-04 01:23:51 作者:如此丿凄凉的微笑°

我真的需要这个帮助...

I Really need help in this ...

我要建在哪里,我需要有出头的DataGrid中的应用程序。

I'm building an application where I need to have somethings in the datagrid.

我想有数据网格有下拉列表,这些列表会会改变取决于其他下拉值,这也取决于previous值。我可以处理这个...

I want to have the datagrid to have drop-down lists, these lists will will change depending on other drop-down values, also depending on previous values. I can handle this ...

我想知道怎么知道如何创建数据网格,即如何添加列(静态),行(动态)。

I want to know how to know how to create the datagrid, i.e. how to add columns (statically), rows (dynamically).

主要地,该数据将被存储在XML文件中。

Mainly, the data will be stored in XML file.

推荐答案

您可以做这样的事情 -

You can do something like this -

//Load XML file and set the DataGrid data context
XElement mymusic = XElement.Load("mymusic.xml");
dg1.DataContext = mymusic.Elements("Album");

XAML中:

Xaml:

<toolkit:DataGrid Name="dg1" ItemsSource="{Binding}"  >
    <toolkit:DataGrid.Columns>
        <toolkit:DataGridTextColumn Header="Album Title" Binding="{Binding Path=Attribute[Title].Value}" HeaderStyle="{StaticResource MyHeaderStyle}" />
        <toolkit:DataGridTextColumn Header="Artist" Binding="{Binding Path=Attribute[Artist].Value}" HeaderStyle="{StaticResource MyHeaderStyle}"/>
        <toolkit:DataGridTextColumn Header="Release Date" Binding="{Binding Path=Attribute[ReleaseDate].Value}" HeaderStyle="{StaticResource MyHeaderStyle}" />
    </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

查看这篇文章的详细信息 -

Check this article for more details -

使用XML数据的一个DataGrid样本