ColorEditBox does not transmit Value into Binding

Editors for WPF Forum

Posted 9 years ago by Markus Springweiler
Version: 10.1.0523
Platform: Silverlight Controls
Environment: Windows 7 (64-bit)
Avatar
Hello,

there is something strange going on when binding against business objects and not using "UpdateSourceTrigger=PropertyChanged":

Take the sample below, start the window, select a color in the first ColorEditBox "c1" and close the popup with the close button in the right upper corner, then move focus by clicking inside the textbox at the bottom (labeled wutg "space for focus"): The ColorEditBox still shows the selected value, but the business object did not receive it at all.

If you restart and instead of closing the popup by the use of the button just move focus to the TextBox, then the value is transfered to the business object.

<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:editors="http://schemas.actiprosoftware.com/winfx/xaml/editors"
        SizeToContent="WidthAndHeight">

    <UniformGrid Columns="2">
        <Label Content="UpdateSourceTrigger&#13;Default (c1):" />
        <editors:ColorEditBox Value="{Binding BindableColor}" x:Name="c1" />

        <Label Content="UpdateSourceTrigger&#13;PropertyChanged (c2):" />
        <editors:ColorEditBox Value="{Binding BindableColor, UpdateSourceTrigger=PropertyChanged}" x:Name="c2" />

        <Label Content="value of control c1:" />
        <TextBlock Text="{Binding Value, ElementName=c1}" />

        <Label Content="value of control c2:" />
        <TextBlock Text="{Binding Value, ElementName=c2}" />

        <Label Content="value of binding:" />
        <TextBlock Text="{Binding BindableColor}" />

        <Label Content="space for focus:" />
        <TextBox />
    </UniformGrid>
</Window>

namespace WpfApplication1
{
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Media;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        private Color? bindableColor;

        public MainWindow()
        {
            this.InitializeComponent();
            this.DataContext = this;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public Color? BindableColor
        {
            get { return this.bindableColor; }
            set
            {
                this.bindableColor = value;
                var handler = this.PropertyChanged;
                if ( handler != null )
                    handler(this, new PropertyChangedEventArgs("BindableColor"));
            }
        }
    }
}

Comments (4)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Markus,

Thanks for the sample, we were able to confirm the issue. It appears the the binding is not updating because a "LostFocus" event is not being raised, atleast not one that would trigger the binding to update. We'll let you know when we figure out a work around/fix.


Actipro Software Support

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Markus,

We've fixed this issue for the next maintenance release. The problem appears to be that the Popup has the focus when it's closed. The focus is then transfered to the Window, without firing a LostFocus event on the PartEditBox.

We will now move the focus to the PartEditBox, if the focus is currently in the Popup when it's closed. This handles the case you described and is completely bypassed if the user has moved the focus by clicking another control (as this correctly raises the LostFocus event).


Actipro Software Support

Posted 9 years ago by Markus Springweiler
Avatar
Thanx.

Quote:
The problem appears to be that the Popup has the focus when it's closed. The focus is then transfered to the Window, without firing a LostFocus event on the PartEditBox.


Sounds like this problem should be reported to Microsoft? Or does the LostFocus event fire just before the Popup is shown at all?
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Markus,

We're not sure if it's an offical bug, but it definitely seems like it.

The LostFocus event is never raised in the case you found. In ahandler for the Popup.Closed event, the Popup.IsKeyboardFocusWithin property is true in this case. The focus is then shifted to the Window (probably because the element that had focus is no longer visible).

It may be that the LostFocus event isn't passed up to the ColorEditBox because something else got "detached".


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.