[英]Xamarin.Forms Get the object of a ListView when an Entry in the ListView is changed
[英]Get width of Entry in Xamarin.Forms
如何在Xamarin.Forms中獲得Entry視圖的寬度? 我正在嘗試使iOS中的條目看起來像Android中的默認條目(下面有一行)。
自定義渲染器:
void SetBorderWidth(Controls.Entry control)
{
Control.BorderStyle = UITextBorderStyle.None;
var myBox = new UIView(new CGRect(0, 40, <INSERT WIDTH HERE>, 1));
myBox.BackgroundColor = control.BorderColor.ToUIColor();
Control.AddSubview(myBox);
}
每當我嘗試插入control.Width,control.WidthRequest,control.MinimumWidthRequest時,都不會發生任何事情。 但是,如果我輸入數字,下面的線會突然顯示。
另外,當我打印出width和widthrequest時,它們的值為-1。
在您的iOS項渲染器,重載Draw
方法和使用CGRect
作為當前提供的Frame
的大小UITextField
,因為這種方法可以多次調用(屏幕旋轉,調整大小,等...保存您UIView
初始創建后只需更新其Frame
。
類似的東西(我沒有我的個人密碼,但這應該是“關閉”):
UIView myBox;
public override void Draw(CGRect rect)
{
base.Draw(rect);
switch (myBox)
{
case null:
myBox = new UIView(new CGRect(0, 40, rect.Width, 1));
Control.AddSubview(myBox);
break;
default:
myBox.Frame = new CGRect(0, 40, rect.Width, 1);
break;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.