UpdateSourceTrigger=PropertyChanged Doesn't Work On Editors

Editors for WPF Forum

Posted 10 years ago by Andy Ver Murlen
Version: 9.1.0504
Platform: .NET 3.5
Environment: Windows XP (32-bit)
Avatar
If you have an editor control (DoubleEditBox, Int32EditBox) that uses a DataBinding for it's value, with UpdateSourceTrigger=PropertyChanged, the binding isn't updated until the control loses focus. UpdateSourceTrigger should update the binding on every valid key press.

Note the following sample code. As you enter values into the standard TextBox, the "Price3 updated" message is output on every key press (for the sake of this simple example, only enter numbers into the text box). However, as you enter values in the DoubleEditBoxes, the "PriceX updated" message is not output on key presses...only when you leave the control.

<Window 
    x:Class="Sample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Editors="clr-namespace:ActiproSoftware.Windows.Controls.Editors;assembly=ActiproSoftware.Editors.Wpf30"
    Title="Window1"
    Width="600"
    Height="300"
    >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Editors:Int32EditBox
            Margin="3"
            Width="100"
            Height="21"
            HorizontalAlignment="Left"
            Value="{Binding Path=Price1, UpdateSourceTrigger=PropertyChanged}"
            Format="C"
            IsNullAllowed="True"
            />
        <Editors:Int32EditBox
            Margin="3"
            Grid.Row="1"
            Width="100"
            Height="21"
            HorizontalAlignment="Left"
            Value="{Binding Path=Price2, UpdateSourceTrigger=PropertyChanged}"
            Format="C"
            IsNullAllowed="True"
            />
        <TextBox
            Margin="3"
            Grid.Row="2"
            Width="100"
            Height="21"
            HorizontalAlignment="Left"
            Text="{Binding Path=Price3, UpdateSourceTrigger=PropertyChanged}"
            />
    </Grid>
</Window>

namespace Sample
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1
    {
        public Window1()
        {
            InitializeComponent();

            DataContext = new ViewModel();
        }
    }
}

using System;
using System.ComponentModel;

namespace Sample
{
    public class ViewModel : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region Fields

        private int? _price1;
        private int? _price2;
        private int? _price3;

        #endregion

        #region Properties

        public int? Price1
        {
            get { return _price1; }
            set
            {
                if (_price1 != value)
                {
                    _price1 = value;
                    Console.WriteLine("Price1 changed");
                    OnPropertyChanged("Price1");
                }
            }
        }

        public int? Price2
        {
            get { return _price2; }
            set
            {
                if (_price2 != value)
                {
                    _price2 = value;
                    Console.WriteLine("Price2 changed");
                    OnPropertyChanged("Price2");
                }
            }
        }

        public int? Price3
        {
            get { return _price3; }
            set
            {
                if (_price3 != value)
                {
                    _price3 = value;
                    Console.WriteLine("Price3 changed");
                    OnPropertyChanged("Price3");
                }
            }
        }

        #endregion
    }
}

Comments (1)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andy,

Please the see following forum post, but this is actually working as designed:

http://www.actiprosoftware.com/Support/Forums/ViewForumTopic.aspx?ForumTopicID=4086

Hope this helps.

[Modified at 08/25/2009 02:02 PM]


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.