C# Xamarin MvvM contentview绑定
我正在用Xaramin开发一个应用程序 在我的解决方案中,我创建了一个ContentView.xaml,作为自定义GUI控件C# Xamarin MvvM contentview绑定,c#,xaml,mvvm,xamarin,C#,Xaml,Mvvm,Xamarin,我正在用Xaramin开发一个应用程序 在我的解决方案中,我创建了一个ContentView.xaml,作为自定义GUI控件 <?xml version="1.0" encoding="UTF-8"?> <ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:test2;assembly=test2"
x:Class="test2.MyView">
<ContentView.BindingContext>
<local:MyViewModel MyValue="1"/>
</ContentView.BindingContext>
<StackLayout>
<Label HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Text="{Binding MyValue}"/>
</StackLayout>
</ContentView>
我还创建了ContentPage.xaml,并在其中添加了自定义控件
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:test2;assembly=test2"
x:Class="test2.MyPage">
<local:MyView />
</ContentPage>
我发现标签从未更新过,为什么?乍一看你应该更换
OnPropertyChanged ("myValue");
与
由于属性名称区分大小写。。。Text=“{Binding MyValue,Mode=“TwoWay”}”/>一个更为最新的答案是:OnPropertyChanged(nameof(MyValue));
OnPropertyChanged ("myValue");
OnPropertyChanged ("MyValue");