Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.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
C# Xamarin MvvM contentview绑定_C#_Xaml_Mvvm_Xamarin - Fatal编程技术网

C# Xamarin MvvM contentview绑定

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-

我正在用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-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");