我有一个基础的自定义控件:
public class TabItem : ContentView
{
public TabItem()
{
SetBinding(HeaderProperty, new Binding("Header"));
}
public static readonly BindableProperty HeaderProperty =
BindableProperty.Create("Header", typeof(string), typeof(TabItem), default(string));
public string Header
{
get { return (string)GetValue(TabItem.HeaderProperty); }
set { SetValue(TabItem.HeaderProperty, value); }
}
}
我从这个类中继承并设置绑定上下文:
public partial class FeedbackView : TabItem
{
public FeedbackView(FeedbackViewModel viewModel)
{
InitializeComponent();
Content.BindingContext = viewModel;
}
}
这是视图模型:
public class FeedbackViewModel : BaseViewModel
{
private string header;
public FeedbackViewModel()
{
Header = "Test Header";
}
public string Header
{
get { return header; }
set
{
header = value;
OnPropertyChanged("Header");
}
}
当我运行它时,头部未绑定到视图模型属性。我有什么明显忘记的东西吗?或者我做错了什么?
FeedbackViewModel
是从BaseViewModel
类继承的,其中已经实现了INotifyPropertyChanged
。我已经在问题中编辑了代码。 - Alexei Malashkevich