我有一個文本框綁定到屬性MinDuration的ViewModel。 MinDuration始終應該小於或等於ViewModel的Duration屬性。所以,我的XAML:儘管正確的「使用最終值」WPF綁定不工作
<TextBox Text="{Binding BasePO.MinDuration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
而且有我的財產:
private double minDuration;
public double MinDuration
{
get { return minDuration; }
set
{
if (value > Duration)
minDuration = Duration;
else
minDuration = value;
OnPropertyChanged("MinDuration");
}
}
所以,讓持續時間= 40。現在,這是結合的結果:
- 如果我把4 - >文本框顯示4
- 如果當時我把5(值是45,現在) - >文本框顯示40(正確的!)
但是,存在這樣的問題:
- 如果我把4 - >文本框顯示4
- 如果然後我把0(該值爲40現在) - >文本框顯示40
- 如果那麼我把,例如,5(現在的值是405) - > TextBox顯示405(爲什麼?)
有結合痕跡:
System.Windows.Data Warning: 90 : BindingExpression (hash=22334206): Update - got raw value '4'
System.Windows.Data Warning: 93 : BindingExpression (hash=22334206): Update - implicit converter produced '4'
System.Windows.Data Warning: 94 : BindingExpression (hash=22334206): Update - using final value '4'
System.Windows.Data Warning: 102 : BindingExpression (hash=22334206): SetValue at level 1 to PO (hash=59829654) using RuntimePropertyInfo(MinDuration): '4'
System.Windows.Data Warning: 95 : BindingExpression (hash=22334206): Got PropertyChanged event from PO (hash=59829654)
System.Windows.Data Warning: 101 : BindingExpression (hash=22334206): GetValue at level 0 from PoTableForm (hash=53931641) using RuntimePropertyInfo(BasePO): PO (hash=59829654)
System.Windows.Data Warning: 101 : BindingExpression (hash=22334206): GetValue at level 1 from PO (hash=59829654) using RuntimePropertyInfo(MinDuration): '4'
System.Windows.Data Warning: 80 : BindingExpression (hash=22334206): TransferValue - got raw value '4'
System.Windows.Data Warning: 84 : BindingExpression (hash=22334206): TransferValue - implicit converter produced '4'
System.Windows.Data Warning: 89 : BindingExpression (hash=22334206): TransferValue - using final value '4'
Поток '<Без имени>' (0x19b4) завершился с кодом 0 (0x0).
System.Windows.Data Warning: 90 : BindingExpression (hash=22334206): Update - got raw value '45'
System.Windows.Data Warning: 93 : BindingExpression (hash=22334206): Update - implicit converter produced '45'
System.Windows.Data Warning: 94 : BindingExpression (hash=22334206): Update - using final value '45'
System.Windows.Data Warning: 102 : BindingExpression (hash=22334206): SetValue at level 1 to PO (hash=59829654) using RuntimePropertyInfo(MinDuration): '45'
System.Windows.Data Warning: 95 : BindingExpression (hash=22334206): Got PropertyChanged event from PO (hash=59829654)
System.Windows.Data Warning: 101 : BindingExpression (hash=22334206): GetValue at level 0 from PoTableForm (hash=53931641) using RuntimePropertyInfo(BasePO): PO (hash=59829654)
System.Windows.Data Warning: 101 : BindingExpression (hash=22334206): GetValue at level 1 from PO (hash=59829654) using RuntimePropertyInfo(MinDuration): '40'
System.Windows.Data Warning: 80 : BindingExpression (hash=22334206): TransferValue - got raw value '40'
System.Windows.Data Warning: 84 : BindingExpression (hash=22334206): TransferValue - implicit converter produced '40'
System.Windows.Data Warning: 89 : BindingExpression (hash=22334206): TransferValue - using final value '40'
System.Windows.Data Warning: 90 : BindingExpression (hash=22334206): Update - got raw value '405'
System.Windows.Data Warning: 93 : BindingExpression (hash=22334206): Update - implicit converter produced '405'
System.Windows.Data Warning: 94 : BindingExpression (hash=22334206): Update - using final value '405'
System.Windows.Data Warning: 102 : BindingExpression (hash=22334206): SetValue at level 1 to PO (hash=59829654) using RuntimePropertyInfo(MinDuration): '405'
System.Windows.Data Warning: 95 : BindingExpression (hash=22334206): Got PropertyChanged event from PO (hash=59829654)
System.Windows.Data Warning: 101 : BindingExpression (hash=22334206): GetValue at level 0 from PoTableForm (hash=53931641) using RuntimePropertyInfo(BasePO): PO (hash=59829654)
System.Windows.Data Warning: 101 : BindingExpression (hash=22334206): GetValue at level 1 from PO (hash=59829654) using RuntimePropertyInfo(MinDuration): '40'
System.Windows.Data Warning: 80 : BindingExpression (hash=22334206): TransferValue - got raw value '40'
System.Windows.Data Warning: 84 : BindingExpression (hash=22334206): TransferValue - implicit converter produced '40'
System.Windows.Data Warning: 89 : BindingExpression (hash=22334206): TransferValue - using final value '40'
正如你所看到的,當我把405 使用最終值「40」,但文本框顯示405和結合工作不適合每個以40開頭的數字(在本例中)。
您定位的是哪個版本的框架? – mm8
我的.net版本是4.0 – gustav
請記住投票贊成有用的答案:) https://stackoverflow.com/help/someone-answers – mm8