我有一个GridControl,其ItemSource绑定到SearchResultViewModel.SearchResults。在这个GridControl中,我有一个DetailDescriptor,它包含另一个GridControl,其ItemSource我也想设置为SearchResultViewModel.SearchResults。
这是我的代码:
<dxg:GridControl ItemsSource="{Binding Path=SearchResultViewModel.SearchResults, Mode=OneWay}">
<dxg:GridControl.DetailDescriptor>
<dxg:ContentDetailDescriptor>
<dxg:ContentDetailDescriptor.ContentTemplate>
<DataTemplate>
<dxg:GridControl ItemsSource="{Binding Path=SearchResultViewModel.SearchResults, Mode=OneWay}" MaxHeight="200">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Heating Deviation" FieldName="HeatingDeviation"/>
</dxg:GridControl.Columns>
</dxg:GridControl>
</DataTemplate>
</dxg:ContentDetailDescriptor.ContentTemplate>
</dxg:ContentDetailDescriptor>
</dxg:GridControl.DetailDescriptor>
SearchResults看起来像这样
public struct SearchResult
{
public SearchResult(SepoContainer sepo, int heatingDeviation)
{
HeatingDeviation = heatingDeviation;
SepoContainer = sepo;
}
public int HeatingDeviation { get; }
public SepoContainer { get; }
}
我想我理解错误,因为我不知道如何继续
答案 0 :(得分:0)
ContentDetailDescriptor.DataContext
会自动设置为行对象,您可以使用RelativeSource
中的Binding
来检索排名GridControl
,从而达到您想要的效果。
<dxg:ContentDetailDescriptor.ContentTemplate>
<DataTemplate>
<dxg:GridControl ItemsSource="{Binding ItemsSource, RelativeSource={RelativeSource AncestorType=dxg:GridControl}, Mode=OneWay}" MaxHeight="200">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Heating Deviation" FieldName="HeatingDeviation"/>
</dxg:GridControl.Columns>
</dxg:GridControl>
</DataTemplate>
</dxg:ContentDetailDescriptor.ContentTemplate>