mvvm light调用RaisePropertyChanged不会触发Property getter(windows phone 8.1)

时间:2016-09-09 09:02:46

标签: c# mvvm windows-phone-8.1 windows-phone mvvm-light

在我的应用程序中,我有一个文本框,用户在其上键入数字。我希望这个拉丁文编号为波斯语,作为用户输入。在调用RaisePropertychanged之后,getter的{​​{1}}未被调用,因此App Ui不会更新。我的代码有什么问题?

这是我的代码

View.xaml

MobileNumber

ViewModel.cs

<Page
x:Class="CustomName.RegistrationPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ShahrMobileBank.Views.Masters.Registration"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:behaviors="using:Template10.Behaviors"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:converter="using:ShahrMobileBank.Converter"
mc:Ignorable="d"
DataContext="{Binding Path=RegistrationPage, Source={StaticResource ViewModelLocator}}">

    <StackPanel Background="{StaticResource RegistrationPageBackgroundColor}" x:Name="LayoutRoot">
        <StackPanel.Resources>
            <converter:RegistrationConverter x:Key="RegistrationConverter"/>
        </StackPanel.Resources>

        <TextBox Style="{StaticResource GenericTextBoxBeforeLogin}"  x:Uid="PhoneNumber" InputScope="Number" Text="{Binding Path=MobileNumber,  Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="{StaticResource MobileNumberMaxLength}"/>
</StackPanel>
</Page>

1 个答案:

答案 0 :(得分:0)

尝试将RaisePropertyChanged行更改为RaisePropertyChanged("MobileNumber");

如果您使用MVVM-Light Code片段(如果已安装,您可以开始输入mvvm,并且会弹出intellisense),您可以查看mvvmpinpc这是PropertyChanged个代码段之一。您可以Tab通过不同的模板字段将其设置为您想要的内容,并且可以为您的编码生活更轻松地提供一些小技巧和窍门。