Description
Describe the bug
I was trying to set a binding to a TextBox that is masked. I have setup an example project of two textboxes, one with and one without a mask, that both have a binding to a property which gets incremented every second.
The TextBox was trying to set a Binding to a TextBox that is Masked. I've noticed that the TextBox without the mask receives the PropertyChanged and updates it's text, the masked one does not.
Steps to Reproduce
Create a new Uwp project and use the MainPage.xaml and MainPage.xaml.cs files within that project.
Start the project and observe the updates from the first, unmasked TextBox in comparison to the masked one.
Expected behavior
A masked TextBox receives the PropertyChanged and updates it's Text just like a regular TextBox.
NuGet Package(s):
Microsoft.NETCore.UniversalWindowsPlatform v6.2.9
Microsoft.Toolkit.Uwp v6.0.0
Microsoft.Toolkit.Uwp.UI v6.0.0
Windows 10 Build Number:
- October 2018 Update (17763)
App min and target version:
Tested with
- Fall Creators Update (16299)
- October 2018 Update (17763)
Visual Studio
- 2019 (version: 16.3.8)
MainPage.xaml
<Page
x:Class="MaskedTextBox.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:local="using:MaskedTextBox"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<StackPanel>
<TextBox Text="{Binding Foo}" />
<TextBox extensions:TextBoxMask.Mask="*******" Text="{Binding Foo}" />
</StackPanel>
</Page>
MainPage.xaml.cs
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.UI.Xaml.Controls;
using MaskedTextBox.Annotations;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace MaskedTextBox
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
DataContext = new ViewModel();
}
}
public class ViewModel : INotifyPropertyChanged
{
private string _foo;
private Task doTask;
public ViewModel()
{
var i = 0;
Foo = "1";
doTask = Task.Run(async () =>
{
while (true)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() => { Foo = (++i).ToString(); });
Thread.Sleep(1000);
}
});
}
public string Foo
{
get => _foo;
set
{
if (value == _foo) return;
_foo = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}