Xamarin.forms 自定义条目控件中的BindableProperty问题
我正在尝试向Xamarin.Forms中的条目添加可绑定属性。这应该允许我通过为HasFocus属性指定一个布尔值来设置/取消设置条目的键盘焦点。我将ReactiveUI用作MVVM框架,RaiseAndSetIfChanged方法隐式引发INotifyPropertyChanged事件(在许多其他地方都可以使用) 在我的FocusedEntry课程中,我无法命中任何断点,并且我没有看到键盘出现。我错过了什么Xamarin.forms 自定义条目控件中的BindableProperty问题,xamarin.forms,reactiveui,bindableproperty,Xamarin.forms,Reactiveui,Bindableproperty,我正在尝试向Xamarin.Forms中的条目添加可绑定属性。这应该允许我通过为HasFocus属性指定一个布尔值来设置/取消设置条目的键盘焦点。我将ReactiveUI用作MVVM框架,RaiseAndSetIfChanged方法隐式引发INotifyPropertyChanged事件(在许多其他地方都可以使用) 在我的FocusedEntry课程中,我无法命中任何断点,并且我没有看到键盘出现。我错过了什么 // XAML <controls:FocusedEntry Text="My
// XAML
<controls:FocusedEntry Text="My custom Entry"
HasFocus="{Binding EntryHasFocus, Mode=TwoWay}"/>
// View Model
private bool _entryHasFocus;
public bool EntryHasFocus
{
get => _entryHasFocus;
private set => this.RaiseAndSetIfChanged(ref _entryHasFocus, value);
}
// Custom View
public class FocusedEntry : Entry
{
public static readonly BindableProperty HasFocusProperty = BindableProperty.Create(
nameof(HasFocus), typeof(bool), typeof(FocusedEntry), false, BindingMode.TwoWay, propertyChanged: OnHasFocusedChanged);
public bool HasFocus
{
get => (bool)GetValue(HasFocusProperty);
set => SetValue(HasFocusProperty, value);
}
private static void OnHasFocusedChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is FocusedEntry entry)
{
bool hasFocus = (bool)newValue;
bool wasFocused = (bool)oldValue;
if (hasFocus == wasFocused) return;
if (hasFocus)
entry.Focus();
else
entry.Unfocus();
}
}
}
//XAML
//视图模型
私人布卢·entryHasFocus;
公共图书馆入口焦点
{
get=>\u entryHasFocus;
private set=>this.RaiseAndSetIfChanged(ref\u entryHasFocus,value);
}
//自定义视图
公共课堂焦点:进入
{
公共静态只读BindableProperty HasFocusProperty=BindableProperty.Create(
nameof(HasFocus)、typeof(bool)、typeof(FocusedEntry)、false、BindingMode.TwoWay、propertyChanged:OnHasFocusedChanged);
公众关注
{
get=>(bool)GetValue(HasFocusProperty);
set=>SetValue(HasFocusProperty,value);
}
HasFocusedChanged上的私有静态void(BindableObject bindable、object oldValue、object newValue)
{
if(可绑定的是FocusedEntry条目)
{
bool hasFocus=(bool)newValue;
bool waspocated=(bool)oldValue;
如果(hasFocus==wasFocused)返回;
如果(hasFocus)
entry.Focus();
其他的
entry.Unfocus();
}
}
}
代码实际上一直都在工作。出于某种原因,VisualStudio没有在我的iPad上更新应用程序,我正在用我的应用程序的旧版本进行测试