Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的INotifypropertyChanged在我的Xamarin Android中不起作用_Android_Xamarin_Xamarin.android_Inotifypropertychanged - Fatal编程技术网

我的INotifypropertyChanged在我的Xamarin Android中不起作用

我的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 =&

我的SeekBar Progress属性更改时需要通知! 我创建了SeekBar和override progress属性! 但是它不起作用

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>