2016-05-17 26 views
0

WPFアプリケーションでは、MVVM LightとFodyを使用しています。私のView-Modelには辞書public Dictionary<string, string> OtherParticipants { get; set; }があります。私のXAMLでのラインがあります:辞書のWPF raiseプロパティ変更イベント

私はメソッドを呼び出す私のビュー・モデルでは
<ListBox Height="350" HorizontalAlignment="Right" Margin="0,0,50,15" 
Name="participantsListBox" VerticalAlignment="Center" 
Width="170" SelectionMode="Single" 
ItemsSource="{Binding OtherParticipants}" 
SelectedItem="{Binding SelectedParticipant}" DisplayMemberPath="Value"/> 

private void NewMessagesReceivedHandler(Dictionary<string, List<BaseMessageDto>> result) 
{ 
    var targetItems = OtherParticipants.Where(p => result.Keys.Any(n => p.Key == n)).ToList(); 

    var dialogueTarget = SelectedParticipant.Value; 

    var dictItem = OtherParticipants.FirstOrDefault(i => i.Value == dialogueTarget); 

    if (targetItems.Contains(dictItem)) 
    { 
     //there is an open dialogue with this user 
     //Dialogue.AddRange(result[dialogueTarget]); 
     result[dialogueTarget].ForEach(m => Dialogue.Add(m)); 
     targetItems.Remove(dictItem); 
    } 

    for (int i = 0; i < targetItems.Count(); i++) 
    { 
     var participantKey = targetItems[i].Key; 
     var participantNameWithNum = targetItems[i].Value; 
     var incomingMessagesCount = result[participantKey].Count; 

     if (_usernameWithNotificationsCountRegex.IsMatch(participantNameWithNum)) 
     { 
      var matches = _usernameWithNotificationsCountRegex.Matches(participantNameWithNum)[0]; 
      var realUser = matches.Groups[1].Value; 
      var currentMessagesCount = Convert.ToInt32(matches.Groups[3].Value); 
      var total = currentMessagesCount + incomingMessagesCount; 

      OtherParticipants[participantKey] = realUser + " (" + total + ")"; 
     } 

     else 
     { 
      OtherParticipants[participantKey] = participantNameWithNum + " (" + incomingMessagesCount + ")"; 
     } 
    } 
} 

メソッド本体は本当に関係ありません、でその背後にある考え方は、内容を変更しませんOtherParticipantsの辞書。問題は、この変更がListBoxに反映されていないことです。どんなアイディアも大歓迎です。
サイドノート:Fodyを使用しているため、すべてのVMに[ImplementPropertyChanged]という属性が付けられています。
編集:コメントにリンクされているObservableDictionaryの現在の実装では、

答えて

0

辞書の実装は、おそらくそのプロパティ名としてBinding.IndexerNameを使用して、プロパティ変更イベントを発生させる必要が動作しません。

関連する問題