我的INotifypropertyChanged在我的Xamarin Android中不起作用
我的SeekBar Progress属性更改时需要通知! 我创建了SeekBar和override progress属性! 但是它不起作用我的INotifypropertyChanged在我的Xamarin Android中不起作用,android,xamarin,xamarin.android,inotifypropertychanged,Android,Xamarin,Xamarin.android,Inotifypropertychanged,我的SeekBar Progress属性更改时需要通知! 我创建了SeekBar和override progress属性! 但是它不起作用 public class MySeekBar : SeekBar,INotifyPropertyChanged { public MySeekBar(Context context) : base(context) { } public override int Progress { get =&
public class MySeekBar : SeekBar,INotifyPropertyChanged
{
public MySeekBar(Context context) : base(context)
{
}
public override int Progress
{
get => base.Progress;
set { base.Progress = value; OnPropertyChange(); }
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChange([CallerMemberName] string propName = null)
{
var change = PropertyChanged;
if (change != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
}
有些东西在你的项目中不起作用。如果您使用的是布局,那么您可能忘了将SeekBar类更改为MySeekBar?此外,您还缺少一些布局所需的构造函数。至于实现,我可能不会覆盖该属性,因为下面的代码对我来说很好
public class MySeekBar : SeekBar, INotifyPropertyChanged
{
public MySeekBar(Context context) : base(context)
{
Initialize();
}
public MySeekBar(Context context, IAttributeSet attrs) : base (context,attrs)
{
Initialize();
}
public MySeekBar(Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle)
{
Initialize();
}
private void Initialize()
{
this.ProgressChanged += (sender, e) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Progress"));
}
public event PropertyChangedEventHandler PropertyChanged;
}
在布局中添加(基本命名空间为SeekB,因此控件应为SeekB.MySeekBar)
Hi。能否添加实际绑定到Progress
的位置以及相关的BindingContext
设置的位置?(为什么要在那里创建一个新的MainActivity
?它没有任何用处。您使用哪个库进行绑定?正如woellij所指出的,您可以显示绑定代码吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<seekb.MySeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/seekBar1" />
</LinearLayout>