簡體   English   中英

mvvm輕調用RaisePropertyChanged不會觸發Property getter(Windows Phone 8.1)

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

在我的應用程序中,我有一個文本框,用戶可以在上面輸入數字。 我想將此拉丁數字以波斯語作為用戶鍵入它。 打完電話后RaisePropertychangedgetterMobileNumber不叫那么應用程序的用戶界面不會更新。 我的代碼有什么問題?

這是我的代碼

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

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);
        }
    }
}

嘗試將RaisePropertyChanged行更改為RaisePropertyChanged("MobileNumber");

如果使用MVVM-Light代碼段(如果已安裝,則可以開始鍵入mvvm,然后將彈出intellisense),您可以查看mvvmpinpc ,它是PropertyChanged代碼段之一。 您可以在不同的模板字段之間進行Tab ,以將其設置為所需的樣式,還可以了解一些小技巧,從而使編碼工作變得更輕松。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM