Posted 15 years ago
by Markus Springweiler
Version: 10.1.0523
Platform: .NET 4.0
Environment: Windows 7 (64-bit)

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.
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 Default (c1):" />
<editors:ColorEditBox Value="{Binding BindableColor}" x:Name="c1" />
<Label Content="UpdateSourceTrigger 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"));
}
}
}
}