Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGrid.RowDetailsTemplate中的DataGrid具有相同的ItemsSource(当前项)_C#_Wpf_Datagrid - Fatal编程技术网

C# DataGrid.RowDetailsTemplate中的DataGrid具有相同的ItemsSource(当前项)

C# DataGrid.RowDetailsTemplate中的DataGrid具有相同的ItemsSource(当前项),c#,wpf,datagrid,C#,Wpf,Datagrid,我对DataGrid.RowDetailsTemplate中的DataGrid有问题 我有一个ObservableCollection类,它有大约20个属性,但没有其他集合。我想把它们分开以便更好地观看。第一个名为“mainGrid”的DataGrid应该显示前10个属性 然后,我定义了DataGrid.rowtailstemplate,以便在用户单击该行时显示其余内容。但它不起作用。RowDetailsTemplate中的第二个数据网格 <Dgv:DataGrid.RowDeta

我对DataGrid.RowDetailsTemplate中的DataGrid有问题

我有一个ObservableCollection类,它有大约20个属性,但没有其他集合。我想把它们分开以便更好地观看。第一个名为“mainGrid”的DataGrid应该显示前10个属性

然后,我定义了DataGrid.rowtailstemplate,以便在用户单击该行时显示其余内容。但它不起作用。RowDetailsTemplate中的第二个数据网格

    <Dgv:DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <Dgv:DataGrid x:Name="dgvRowDetails">

                <Dgv:DataGrid.Columns>
                  <Dgv:DataGridTextColumn Header="Parameter 1" 
                               Binding="{Binding Parameter1}" />
                   <Dgv:DataGridTextColumn Header="Parameter 2" 
                               Binding="{Binding Parameter2}" />
                    </Dgv:DataGrid.Columns>
                </Dgv:DataGrid>
        </DataTemplate>
    </Dgv:DataGrid.RowDetailsTemplate>

它只显示行详细信息中的标题(当我单击行时),而不显示内容。 “输出”选项卡未显示任何绑定错误

我想我也需要一个ItemsSource,但我不知道如何实现它,因为其他属性引用当前或selectedItem

但这个例子很好:

    <Dgv:DataGrid.RowDetailsTemplate>
        <DataTemplate>
         <StackPanel>
          <TextBlock Text = "{Binding Parameter1}" />
          <TextBlock Text = "{Binding Parameter2}" />
         </StackPanel>
        </DataTemplate>
    </Dgv:DataGrid.RowDetailsTemplate>

但我真的想要一个数据网格,因为它的标题等等

我正在使用.NET3.5

非常感谢

试试这个

 <Dgv:DataGrid x:Name="dgvRowDetails" ItemsSource="{Binding}">

你不可能真正做到这一点
ItemsSource
希望是一个
IEnumerable
,您需要的是为它提供一个项目

这是一种很难实现的方法。在对象的类中,绑定外部datagrid的ItemSource以定义一个新属性,该属性以某种
IEnumerable

public class MyClass
{
    public IEnumerable<MyClass> AsIEnumerable
    {
        get
        {
            yield return this;
        }
    }
}
公共类MyClass
{
公共IEnumerable可枚举
{
得到
{
收益回报这一点;
}
}
}
XAML

//内部数据网格
//Datacontext是MyClass对象

你说你想要标题。我的建议是使用合适的工具创建标题,而不是因为有圆就把正方形塞进圆中。

嘿,Ethicalologics,谢谢你的帖子,但这不起作用。嘿,Shoe,非常感谢你。你的“黑客”确实有用。但是由于收益率,您不能使用ObservableCollection,因此我不能修改DataGrid中的值。尽管如此,我还是花了一些时间,用标签和文本框创建了自己的“数据网格”。现在我有了最好的控制力和灵活性。不过还是要谢谢你!你不必使用收益率。您可以构建一个新的ObservableCollection并返回添加到其中的
this
//Inner datagrid
//Datacontext is MyClass object
<Dgv:DataGrid x:Name="dgvRowDetails" 
              AutoGenerateColumns="False" 
              ItemsSource="{Binding AsIEnumerable}">
    <Dgv:DataGrid.Columns>
       <Dgv:DataGridTextColumn Header="Parameter 1" 
                               Binding="{Binding Path=Parameter1}" />
       <Dgv:DataGridTextColumn Header="Parameter 2" 
                               Binding="{Binding Path=Parameter2}" />
    </Dgv:DataGrid.Columns>
</Dgv:DataGrid>