UpdateSourceEventName doesn't work
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
**Summary**: UpdateSourceEventName doesn't seem to work as intended.
**Platform**: Tested on Windows
I have an editor with its text bound to property of a viewmodel. I'm using a converter to do a on-the-fly conversion. XAML looks like following:
```xaml
```
The problem is that UpdateSourceEventName doesn't seem to have any effect on the binding. When user presses a single key, it gets converted to long, and then converted back to the editor. Effectively, after inputting "12", user gets "1.002", because "1" gets immediately converted by the converter into "1.00".
I'd like the binding to be fired after user leaves the editor, such as in WPF (UpdateSourceTrigger=LostFocus).
For reference, source of the converter:
```csharp
public class StringToMoneyConverter : IValueConverter
{
private Regex valueRegex = new Regex(@"^([0-9]+)\.?([0-9]+)?$");
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is long?)
{
var lValue = (long?)value;
return $"{lValue.Value / 100}.{lValue.Value % 100:00}";
}
else if (value == null)
{
return String.Empty;
}
return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string sValue)
{
var match = valueRegex.Match(sValue);
if (match.Success)
{
long result = long.Parse(match.Groups[1].Value) * 100;
if (match.Groups[3].Success)
result += long.Parse(match.Groups[2].Value);
return (long?)result;
}
return (long?)null;
}
return Binding.DoNothing;
}
}
```
Contributor guide
Research direction
Start with the XAML binding shown in the issue and reproduce it on Windows using the provided StringToMoneyConverter and an Editor bound two-way to a view-model property. Trace how UpdateSourceEventName handles Unfocused and verify the fix with a regression test showing that typing "12" does not update the source until the editor loses focus.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100