我有以下课程,我想绑定到一个网格,但它没有工作 - 任何指导赞赏
第1课:
public class Assessments
{
public AssessmentHeader AssessmentHeader { get; set; }
public ObservableCollection<AssessmentSurveyHeaders> AssessmentSurveys { get; set; }
}
Class 2:
public class AssessmentSurveyHeaders
{
public AssessmentSurvey AssessmentSurvey { get; set; }
public ObservableCollection<SurveyLines> AssessmentSurveyLines { get; set; }
}
Class 3:
public class AssessmentSurvey
{
public Guid SurveyId{ get; set; }
public string Description{ get; set; }
}
网格绑定:
<data:DataGrid x:Name="QuestionGrid" ColumnHeaderStyle="{StaticResource DataGridHeaderGlassEffect}" AutoGenerateColumns="False" ItemsSource="{Binding _Assessments, Mode=TwoWay}" HorizontalAlignment="Stretch" >
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Header="Assessment">
<data:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<HyperlinkButton x:Name="AssessmentLink" Tag="{Binding AssessmentHeader.AssessmentGuid}" Content="{Binding AssessmentHeader.AssessmentGuid}" Click="AssessmentLink_Click"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn Header="SurveyId">
<data:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<data:DataGrid x:Name="SurveysGrid" AutoGenerateColumns="False" ItemsSource="{Binding AssessmentSurveys, Mode=TwoWay}" HorizontalAlignment="Stretch" >
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Id" Binding="{Binding AssessmentSurveys.AssessmentSurvey.SurveyGuid, Mode=TwoWay}" IsReadOnly="True"/>
<data:DataGridTextColumn Header="Description" Binding="{Binding AssessmentSurveys.AssessmentSurvey.Description, Mode=TwoWay}" IsReadOnly="True"/>
</data:DataGrid.Columns>
</data:DataGrid>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
答案 0 :(得分:0)
ID和描述已经与ItemsSource的AssessmentSurveys绑定。
换句话说,您不需要编写每个子项的 AssessmentSurveys 。
请在下面尝试。
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="Id" Binding="{Binding AssessmentSurvey.SurveyGuid, Mode=TwoWay}" IsReadOnly="True"/>
<data:DataGridTextColumn Header="Description" Binding="{Binding AssessmentSurvey.Description, Mode=TwoWay}" IsReadOnly="True"/>
</data:DataGrid.Columns>