![](/img/trans.png)
[英]Set value of DependencyProperty and preserve OneWayToSource-Binding
[英]WPF TargetNullValue returning value when the textbox's binding is set to OneWayToSource
我有這個XAML文本框
<TextBox Text="{Binding ProdFilter.Min, Mode=OneWayToSource,
UpdateSourceTrigger=PropertyChanged, TargetNullValue=''}"
Width="50" DockPanel.Dock="Right" TabIndex="3" />
與此屬性綁定:
public double? Min
{
get { return min; }
set
{
if (value == null)
value = 0;
min = value;
OnPropertyChanged("Min");
}
}
我的問題是,當程序啟動時或當用戶清除文本時,文本框的文本設置為“ 0”。 我不知道這種行為是否正確,因為我使用的是OneWayToSource,但是我希望在文本為空(並且文本保持為空!)時將屬性設置為null。
有任何想法嗎? 謝謝!
這是因為WPF設置屬性后,即使綁定為OneWayToSource
,也會從屬性中重新讀取該值。 請參閱此問題的答案以獲取可能的解決方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.