xamarin.forms - 如果 Grid.Row 已知,如何获取网格行的子级

标签 xamarin.forms

我正在开发 xamarin.forms 应用程序,但我有无法解决的问题。

1) 我有多个 Grid一个接一个,包含按钮、标签和图像。现在,单击按钮时,我想更改图像或将其向下旋转。但不知何故,我无法做到。

我的第一次尝试是获取按钮的父级并使用 FindByName 查找图像方法。但是FindByName返回null,但调试时我可以在父级中看到网格。

我的第二次尝试是获取按钮行并找到该行中的所有控件。因为我的图像与按钮在同一行。

我的结构是这样的

When I click on arrow(i.e image) it should be changed

我的网格工作正常,但只有旋转问题。

pubic void OnButtonClicked(object sender, EventArgs e)
{
   var SenderButton = (Button)sender;
   var row = Grid.GetRow(SenderButton); // Here i get row = 0 but dont know how to find other controls on same row.

   Image upimage = SenderButton.Parent.FindByName<Image>("imageExpand");  // imageExpand is my image name in grid.
   upimage.Source = "upimage.png";
}

这里upimagenull .

非常感谢你。

最佳答案

I'm only replying to your first question



你没看错,你可以得到附加的可绑定(bind)属性的值Grid.Row使用 public static int GetRow(BindableObject bindable) .现在过滤网格的 child 很容易。

var button = (Button)sender;
var row = Grid.GetRow(button);
var grid = button.Parent as Grid;
//assuming the image is in column 1
var image = grid.Children.Where(c => Grid.GetRow(c) == row && Grid.GetColumn(c)==1);

关于xamarin.forms - 如果 Grid.Row 已知,如何获取网格行的子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39475959/

相关文章:

Xamarin : Should you use an MVVM library and which is the best

xaml - Xamarin.Forms中的编译错误 “Can not set the content of ListView as it doesn' t具有ContentPropertyAttributte”

data-binding - Xamarin 将双向数据绑定(bind)到 RealmObject 引发错误

ios - 如何启用滑动手势以在 Xamarin 表单 UWP 中引入母版页?

c# - get 属性的绑定(bind)问题;与 get 对比;放;在 Xamarin.Android 中

xamarin.forms Android 发布版本仅适用于启用快速部署

xamarin.forms - 适用于 Visual Studio 2017 for Mac 的 Prism 模板包

c# - Xamarin 表单级联样式表 (CSS) 不工作。加载样式文件失败

Xamarin.forms iOS 模拟器未启动

c# - Xamarin 权限插件 RequestPermissionsAsync 未返回