WPF TargetNullValue returns when text field binding is set to OneWayToSource

I have this xaml text box

<TextBox Text="{Binding ProdFilter.Min, Mode=OneWayToSource,
   UpdateSourceTrigger=PropertyChanged, TargetNullValue=''}"
   Width="50" DockPanel.Dock="Right" TabIndex="3" />

tied to this property:

        public double? Min
        {
            get { return min; }
            set
            {
                if (value == null)
                    value = 0;
                min = value;
                OnPropertyChanged("Min");
            }
        }

The problem is that when the program starts or when the user clears the text, the text of the text field is set to "0". I don't know if this behavior is correct, because I use OneWayToSource, but I need my property to be set to null when the text is empty (and the text remains empty!)

Any ideas? Thank!

+5
source share
1 answer

, WPF , OneWayToSource. . .

+6

All Articles