分类XAML代码段 - >
<StackLayout Grid.Column ="1" Grid.Row ="0" Orientation ="Vertical" BackgroundColor ="White" Padding ="10" HorizontalOptions ="FillAndExpand">
<Image Source ="banking.png" HorizontalOptions ="CenterAndExpand "/>
<Label Text ="Finance" FontSize ="Small " HorizontalOptions ="FillAndExpand" HorizontalTextAlignment ="Center"/>
</StackLayout>
<StackLayout Grid.Column ="2" Grid.Row ="0" Orientation ="Vertical" BackgroundColor ="White" Padding ="10" HorizontalOptions ="FillAndExpand">
<Image Source ="legal.png" HorizontalOptions ="CenterAndExpand "/>
<Label Text ="Legal" FontSize ="Small " HorizontalOptions ="FillAndExpand" HorizontalTextAlignment ="Center"/>
</StackLayout>
请帮忙 . 我需要的是能够将名为“CategoryName”的变量传递给我的SearchAPI控制器并检索具有该类别的所有数据库条目 . 我的SearchAPIController如下所示
[Route("api/Oppotunities/Search/{keyword}")]
[ResponseType(typeof(List<Oppotunity>))]
public async Task<IHttpActionResult> GetOppotunitiesByKeyword(string keyword)
{
List<Oppotunity> oppotunities = db.Oppotunities
.Where(oppotunity => oppotunity.Title.Contains(keyword)
|| oppotunity.Description.Contains(keyword)
|| oppotunity.Category.Contains(keyword)
|| oppotunity.Organisation.Contains(keyword)).ToList();
if (oppotunities == null)
{
return NotFound();
}
return Ok(oppotunities);
}
2 回答
您需要在xaml中为
Image
控件命名比,在相同文件的代码后面,创建
TapGestureRecognizer
并添加到Image
我建议你重新构建你的XAML代码设计 . 查看您的代码段,发布的屏幕截图,以及从您的评论到_281440的答案,您可以通过创建custom view并将信息绑定到它来简化您的工作 . 例如,以下代码:
可以变成自定义控件,如:
这将通过 a lot 简化您的XAML . 然后,您可以实现Action或EventHandler属性来处理特定视图的点击时间,然后可以将您的自定义控件转换为:
因为看起来(从你的图像)你将重复使用相同的视图,你应该看看实现FlexLayout而不是
Grid
并使用Binding
s将图像文件,文本和点击处理程序附加到视图,将进一步简化您的XAML和代码结构!