下面是我的集合视图的图像,其中包含返回的 CaseName、ReportName、Court 和 Judges 查询。有两个按钮(索引和判断)。当用户点击或单击任何一个按钮时,例如当用户点击第一个单元格或视单元的索引按钮时,我将能够选择 INKUMSAH V. THE REPUBLIC 字段并发送到下一页:一个参数。
显示警报是为了告诉我是否已检索到案例名称。只是确定一下。
如果你们中的任何人能够向我伸出援助之手,我将非常高兴。非常感谢您,提前。
<CollectionView x:Name="CasesCollectionView"
ItemsSource="{Binding ReportedCasesList}"
Grid.Row="2">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame x:Name="frame"
CornerRadius="10"
Margin="10,0,10,10"
HasShadow="True">
<StackLayout>
<Label x:Name="Case"
TextColor="Red"
Text="{Binding Source={x:Reference Case}, Path=BindingContext.CaseName}"
FontSize="13"
FontAttributes="Bold"
Padding="0,0,0,10" />
<Label x:Name="Report"
TextColor="Black"
FontSize="12"
Text="{Binding ReportName}" />
<Label x:Name="Court"
TextColor="Black"
FontSize="12"
Text="{Binding CourtName}" />
<Label x:Name="Judge"
TextColor="Black"
FontSize="12"
Text="{Binding Judges}"
HorizontalTextAlignment="End"
FontAttributes="Italic"
Padding="0,10,0,0" Margin="0,0,0,10" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button x:Name="IndexButton"
TextColor="White"
BackgroundColor="Red"
FontSize="12"
Text="Index"
Grid.Column="0" Margin="5,0,5,0"
Command="{Binding Source={x:Reference CasesCollectionView}, Path=BindingContext.GoToCaseIndexCommand}"/>
<Button x:Name="JudgmentButton"
TextColor="White"
BackgroundColor="Red"
FontSize="12"
Text="Judgment"
Grid.Column="1" Margin="5,0,5,0"
Command="{Binding Source={x:Reference CasesCollectionView}, Path=BindingContext.GoToCaseJudgmentCommand}"/>
</Grid>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
[ObservableProperty]
public string? caseName;
[RelayCommand]
public async Task GoToCaseIndex()
{
if (Application.Current?.MainPage != null)
await Application.Current.MainPage.DisplayAlert("Cases",
CaseName, "OK");
await Shell.Current.GoToAsync(nameof(AreasOfLawResultsPage));
}
[RelayCommand]
public async Task GoToCaseJudgment()
{
if (Application.Current?.MainPage != null)
await Application.Current.MainPage.DisplayAlert("Cases",
CaseName, "OK");
await Shell.Current.GoToAsync(nameof(AreasOfLawResultsPage));
}
这非常简单...您可以将选定的报告案例(用户单击“索引”、“判断”的案例)检索到您的按钮命令
为按钮添加CommandParameter,例如
<Button x:Name="IndexButton"
TextColor="White"
BackgroundColor="Red"
FontSize="12"
Text="Index"
Grid.Column="0" Margin="5,0,5,0"
Command="{Binding Source={x:Reference CasesCollectionView}, Path=BindingContext.GoToCaseIndexCommand}"
CommandParameter={Binding .}/>
在视图模型中
[RelayCommand]
public async Task GoToCaseIndex(object obj)
{
if(obj is ReportedCase case)
{
var caseName = case.CaseName;
// do some stuff
}
}
注意*:我假设 ReportedCase 作为您的模型。