以下是我的问题:
我创建了一个从WEntryRenderer派生的EntryRenderer。我的问题很简单,我从EntryRenderer中高估了EntryRenderer方法,因为如果出了问题,我想停止焦点传播。问题是这个方法从来没有被调用..。我不明白为什么,有谁给我带了牙轮吗?
/// <summary>
/// Renderer Android pour le contrôl WEntry
/// </summary>
public class WEntryRenderer : EntryRenderer
{
protected override void OnFocusChanged(bool gainFocus, [GeneratedEnum] FocusSearchDirection direction, Rect previouslyFocusedRect)
{
bool dontSetFocus = false;
//if (Something goes wrong)
//{
// dontSetFocus = true;
//}
if (!dontSetFocus)
{
base.OnFocusChanged(gainFocus, direction, previouslyFocusedRect);
}
}}
这里有一个替代解决方案:
//分支事件
private void SubscribeEvents()
{
//Emit au changement de focus
this.Control.FocusChange += WEntryRenderer_FocusChanged;
}//代码相关
private void WEntryRenderer_FocusChanged(object sender, FocusChangeEventArgs e)
{
//Si on perd le focus, on emet l'événement PropertyValidated de la propriété lié au composant
if (!e.HasFocus && wentryRequiringFocus == null)
{
//Emet l'événementValidated
this.currentWEntry.ModelPropertyBinding.OnPropertyValidated();
//Si le composant possède des erreur et qu'aucune requête de focus n'est en cours, le composant requiert le focus
if (!ListManager.IsNullOrEmpty(this.currentWEntry.ErrorList))
{
//Place le focus sur le control courant
this.currentWEntry.Focus();
//On indique à la classe que le focus est demandé par cette instance
WEntryRenderer.wentryRequiringFocus = this.currentWEntry;
}
}
//Si le focus a été demandé par l'instance courante, on libère la demande à la récupération du focus
else if (e.HasFocus && WEntryRenderer.wentryRequiringFocus == this.currentWEntry)
{
//Libère la requête de focus
WEntryRenderer.wentryRequiringFocus = null;
}
}我不喜欢这个解决方案,因为即使您强制将焦点放在实际实例上,焦点已经设置为另一个视图.它在ListView内部引发了许多问题
发布于 2017-09-04 12:09:11
你用正确的程序集属性来装饰它吗?
[assembly: ExportRenderer (typeof (Entry), typeof (WEntryRenderer))]
namespace YourProject.iOS
{
...
}需要这样做才能指示Xamarin表单,对于指定为第一个参数的类型(Entry),需要调用此呈现程序。
更新:
可以尝试的另一种解决方案是签入OnElementPropertyChanged中的IsFocused属性:
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == "IsFocused")
{
// Do something
}
}https://stackoverflow.com/questions/46035836
复制相似问题