开发者

WPF TargetNullValue returning value when the textbox's binding is set to OneWayToSource

开发者 https://www.devze.com 2023-02-14 07:32 出处:网络
I have this xaml textbox <TextBox Text=\"{Binding ProdFilter.Min, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, TargetNullValue=\'\'}\"

I have this xaml textbox

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

binded to this this property:

        public double? Min
        {
            get { return min; }
            set
            {
                if (value == null)
                    value = 0;
                min = value;
                O开发者_如何学CnPropertyChanged("Min");
            }
        }

The problem I have is that when the program starts or when there user clears the text, the textbox's text is set to "0". I don't know if this behaviour is right, because i'm using OneWayToSource, but i'd like my property to be set to null when text is empty (and the text to remain empty!)

Any ideas? Thanks!


This is because WPF re-reads the value from the property after it sets it even though the binding is OneWayToSource. Please see the answer to this question for possible workaround.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号