Skip to content

Document resolution in https://github.com/AvaloniaUI/Avalonia/issues/19471#issuecomment-4038448771 #910

@luke-whos-here

Description

@luke-whos-here

I've looked at this issue. TargetNullValue and FallbackValue should indeed be used.

You mention:
Adding TargetNullValue=0 and FallbackValue=0 prevents visible binding failures in app code, but the control/binding still logs the cast error in some configurations without LostFocus.

That is actually a common issue with those two properties. They're typed as object: by specifying them like this in XAML, you're actually setting their value to the string "0" instead of the int 0. That's why you're noticing internal cast errors.

Type them explicitly in XAML, and notice that there's no error anymore:

<NumericUpDown.Value>
  <Binding Path="Units">
    <Binding.TargetNullValue><x:Int32>0</x:Int32></Binding.TargetNullValue>
    <Binding.FallbackValue><x:Int32>0</x:Int32></Binding.FallbackValue>
  </Binding>
</NumericUpDown.Value>

A bit verbose, but it works.

Originally posted by @MrJul in #19471

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions