2017-07-14 3 views
0

私は、ViewModelのプロパティMinDurationにTextBoxをバインドしています。 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をしましょう。さて、その結合の結果である: - 私は5を入れ、その後場合>テキストボックスが表示さ4

  • (値が今45です) - 私は4を置けば

    • >のテキストボックスには、40(正解!)が表示さ

    しかしが、問題がある: - 私は0を入れ、その後場合>テキストボックスが表示さ4

  • (値が今40です) - 私は4を置けば

    • >テキストボックスは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' 
    

    あなたが見ることができるように、「40」が、テキストボックスが表示さ405とし、最終的な値を使用して405 結合のために働いていませんすべての数字は40から始まります(この例では)。

  • +0

    どのバージョンのフレームワークをターゲットにしていますか? – mm8

    +0

    私の.netバージョンは4.0 – gustav

    +0

    です。参考にしてください。https://stackoverflow.com/help/someone-answers – mm8

    答えて

    1

    これは実際には.NET Framework 4.5で修正された古いバグです。詳細については、@ Mattの回答を参照してください。

    Bound WPF TextBox is not updating value when the bound property enforces some business rules

    あなたは回避策がここで提案しようとする場合がありますいくつかの理由から4.5にアップグレードすることができない場合は、次の

    WPF - MVVM - Textbox getting out of sync with viewmodel property

    をそれは最も古い公式にサポートされているバージョンのことに言及しなければなりません.NET Frameworkは現在4.5.2なので、結局はアップグレードすることをお勧めします。https://blogs.msdn.microsoft.com/dotnet/2015/12/09/support-ending-for-the-net-framework-4-4-5-and-4-5-1/

    関連する問題