我绑定了DataGrid
中的值列表。
添加了datagrid行模板。当选择的行我显示该模板。在我的模板中,我有一个DataGrid
具有不同的列表(ObservableCollection
)。 Array
具有价值,但未在DataGrid
中更新。
我的代码:
XAML
<DataGrid IsReadOnly="True" ItemsSource="{Binding Patients}" Grid.Row="1" Grid.Column="0" AutoGenerateColumns="False" CanUserResizeColumns="True" CanUserReorderColumns="False"
SelectedItem="{Binding SelectedPatient}" SelectionMode="Single">
<DataGrid.InputBindings>
<MouseBinding
MouseAction="LeftDoubleClick"
Command="{Binding SingleClickCommand}" CommandParameter="{Binding ElementName=myGrd, Path=SelectedPatient}" />
</DataGrid.InputBindings>
<DataGrid.Columns>
<DataGridTextColumn Header="#" Binding="{Binding Salutation}" Width="*"/>
<DataGridTextColumn Header="FirstName" Binding="{Binding FirstName}" Width="*"/>
<DataGridTextColumn Header="LastName" Binding="{Binding LastName}" Width="*"/>
<DataGridTextColumn Header="Gender" Binding="{Binding Gender}" Width="*"/>
<DataGridTextColumn Header="Age" Binding="{Binding Age}" Width="*"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DockPanel Background="GhostWhite">
<Grid Margin="30,10,30,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="1" Grid.Column="0" Margin="0,0,0,50">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DataGrid IsReadOnly="True" Grid.Row="0" Grid.Column="0" AutoGenerateColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False" ItemsSource="{Binding PatientVisits}">
<DataGrid.Columns>
<DataGridTextColumn Header="Visit Date" Width="Auto" Binding="{Binding Complaint}"/>
<DataGridTextColumn Header="Medication" Width="Auto" Binding="{Binding Medication}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid>
</DockPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid
Cs代码 我在行选择上添加了以下代码
public void GetVisitHistoryForSelectedPatient()
{
PatientVisits = new ObservableCollection<StudyVisitModel>
{
new StudyVisitModel{VisitDate=DateTime.Now,Medication="Tablets and tonics"},
new StudyVisitModel{VisitDate=DateTime.Now,Medication="Tablets and tonics"}
};
OnPropertyChanged("PatientVisits");
}