Я пытаюсь создать страницу содержимого форм Xamarin, которая содержит сетку с формой ввода, а затем на той же странице сетку данных, содержащую связанные данные. Итак, у меня есть хирургический случай, а затем в сетке данных будут находиться сотрудники, связанные с этим хирургическим случаем. Я не уверен, как связать таблицу данных о персонале с хирургическим случаем, чтобы он отображал персонал только из этого одного случая. Я включаю все это в одну и ту же модель представления. Как передать SxCaseId из формы ввода в сетку данных?
public class SxCaseMasterViewModel : ViewModelBase
{
private ISxCaseDataService _sxCaseDataService;
private ICaseStaffJoinForSxCaseDataService _caseStaffJoinForSxCaseDataService;
private SxCase _selectedSxCase;
private CaseStaffJoin _selectedCaseStaffJoin;
private CaseStaffJoin caseStaffJoin;
private ObservableCollection<CaseStaffJoin> _caseStaffJoins;
private ObservableCollection<SxCase> _sxCases;
public SxCaseMasterViewModel(IConnectionService connectionService,
INavigationService navigationService, IDialogService dialogService,
ICaseStaffJoinForSxCaseDataService caseStaffJoinForSxCaseDataService,
ISxCaseDataService sxCaseDataService) : base(connectionService, navigationService, dialogService)
{
_sxCaseDataService = sxCaseDataService;
_caseStaffJoinForSxCaseDataService = caseStaffJoinForSxCaseDataService;
SxCases = new ObservableCollection<SxCase>();
CaseStaffJoins = new ObservableCollection<CaseStaffJoin>();
}
public ICommand UpdateSxCaseCommand => new Command(OnUpdateSxCase);
public SxCase SelectedSxCase
{
get => _selectedSxCase;
set
{
_selectedSxCase = value;
OnPropertyChanged();
}
}
public ObservableCollection<SxCase> SxCases
{
get => _sxCases;
set
{
_sxCases = value;
OnPropertyChanged();
}
}
public override async Task InitializeAsync(object sxCase)
{
SelectedSxCase = (SxCase)sxCase;
}
public CaseStaffJoin SelectedCaseStaffJoin
{
get => _selectedCaseStaffJoin;
set
{
_selectedCaseStaffJoin = value;
OnPropertyChanged();
}
}
public ObservableCollection<CaseStaffJoin> CaseStaffJoins
{
get => _caseStaffJoins;
set
{
_caseStaffJoins = value;
OnPropertyChanged();
}
}
private async void OnUpdateSxCase(object sxCase)
{
await _sxCaseDataService.UpdateSxCase(SelectedSxCase.SxCaseId, SelectedSxCase);
OnPropertyChanged();
await _dialogService.ShowDialog("Case details updated.", "Success", "OK");
await _navigationService.NavigateToAsync<SxCaseViewModel>();
//await _navigationService.PopToRootAsync();
}
public ICommand DeleteSxCaseCommand => new Command(async () =>
{
await _sxCaseDataService.DeleteSxCase(SelectedSxCase.SxCaseId);
await _dialogService.ShowDialog("Case deleted.", "Success", "OK");
await _navigationService.NavigateToAsync<SxCaseViewModel>();
});
}
<ContentPage.Content>
<Grid>
<StackLayout BackgroundColor="Yellow">
<Grid Grid.Row="0" Padding="10" x:Name="MasterGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="CaseId" Grid.Row="0" Grid.Column="0"/>
<Label Text="{Binding SelectedSxCase.SxCaseId}" Grid.Row="0" Grid.Column="1"/>
<Label Text="Dos" Grid.Row="1" Grid.Column="0"/>
<renderers:SfDatePicker x:Name="dos" BindingContext="{Binding SelectedSxCase.Dos}" Grid.Row="1" Grid.Column="1" HorizontalOptions="StartAndExpand"/>
<Label Text="EyeId" Grid.Column="0" Grid.Row="2"/>
<Entry Text="{Binding SelectedSxCase.EyeId, Mode=TwoWay}" Grid.Column="1" Grid.Row="2"/>
<Label Text="Facesheet" Grid.Column="0" Grid.Row="3"/>
<Entry Text="{Binding SelectedSxCase.Facesheet, Mode=TwoWay}" Grid.Column="1" Grid.Row="3"/>
<Label Text="Record" Grid.Column="0" Grid.Row="4"/>
<Entry Text="{Binding SelectedSxCase.Record, Mode=TwoWay}" Grid.Column="1" Grid.Row="4"/>
<Label Text="Complication" Grid.Column="0" Grid.Row="5"/>
<Switch IsToggled="{Binding SelectedSxCase.Complication, Mode=TwoWay}" Grid.Column="1" Grid.Row="5"/>
<Label Text="ReturnOr" Grid.Column="0" Grid.Row="6"/>
<Switch IsToggled="{Binding SelectedSxCase.ReturnOr, Mode=TwoWay}" Grid.Column="1" Grid.Row="6"/>
<Label Text="PhysicianId" Grid.Column="0" Grid.Row="7"/>
<Entry Text="{Binding SelectedSxCase.PhysicianId, Mode=TwoWay}" Grid.Column="1" Grid.Row="7"/>
<Label Text="{Binding SelectedSxCase.Physician}"/>
<Button Text="Update Case" Style="{StaticResource RegularButton}"
Command="{Binding UpdateSxCaseCommand}" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
<Button Text="Delete Case" Style="{StaticResource RegularButton}"
Command="{Binding DeleteSxCaseCommand}" Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
</Grid>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="5*" x:Name="firstRow" />
<RowDefinition Height="3*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<datagrid:SfDataGrid
ItemsSource="{Binding CaseStaffJoins, Mode=TwoWay}" AllowEditing="True" AutoGenerateColumns="True">
</datagrid:SfDataGrid>
</Grid>
</StackLayout>
</Grid>
</ContentPage.Content>