简体   繁体   English

mvvm轻调用RaisePropertyChanged不会触发Property getter(Windows Phone 8.1)

[英]mvvm light calling RaisePropertyChanged doesn't fire Property getter(windows phone 8.1)

in my application I have a textbox that user type a number on it. 在我的应用程序中,我有一个文本框,用户可以在上面输入数字。 I want to this Latin number to Persian one as user type it. 我想将此拉丁数字以波斯语作为用户键入它。 after calling RaisePropertychanged the getter of MobileNumber not called so App Ui doesn't update. 打完电话后RaisePropertychangedgetterMobileNumber不叫那么应用程序的用户界面不会更新。 what is the problem with my code? 我的代码有什么问题?

here is my code 这是我的代码

View.xaml View.xaml

<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>

ViewModel.cs ViewModel.cs

public class RegistrationPageViewModel : ViewModelBase
{
    private string _mobileNumber;

    public String MobileNumber
    {
        get
        {
            return _mobileNumber;
        }
        set
        {
            _mobileNumber = LangUtil.ConvertEnNumberToFaNumber(value); // this converts the number from Latin to Persian
            RaisePropertyChanged(() => MobileNumber);
        }
    }
}

Try changing the RaisePropertyChanged line to RaisePropertyChanged("MobileNumber"); 尝试将RaisePropertyChanged行更改为RaisePropertyChanged("MobileNumber");

If you use the MVVM-Light Code snippets (if installed, you can start typing mvvm, and intellisense will pop up), you can look at mvvmpinpc which is one of the PropertyChanged code snippets. 如果使用MVVM-Light代码段(如果已安装,则可以开始键入mvvm,然后将弹出intellisense),您可以查看mvvmpinpc ,它是PropertyChanged代码段之一。 You can Tab through the different template fields to set it up to what you want, as well as possibly shed any light on little tips and tricks to make your coding life easier. 您可以在不同的模板字段之间进行Tab ,以将其设置为所需的样式,还可以了解一些小技巧,从而使编码工作变得更轻松。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM