2012-04-19 13 views
0

私は現在、プリズムIEventAggregatorを使用して、異なるモジュールの2つのビュー間でwpf通信を試しています。パブリッシングモジュールとサブスクリプションモジュールが正常に動作しています。何らかの理由でサブスクライバUIが更新されない理由を理解できません。サブスクライバモジュールにmsgboxを表示するボタンを配置してください。私は適切にINotifyPropertyChangedを実装すると思います。Wpf MVVM UIはモジュール化、イベント・ジェネレータの実装を更新しません

私がサブスクライバビューのコードビハインドにサブスクライブすると、それがうまくいくように動作します....それは間違ったやり方ですか?私を修正してください。ありがとう。

モジュールメッセージを渡すための別のクラス。

Public Class Module1ViewModel 

Private _msgsend As String 
Public WriteOnly Property MessageSend As String 
    Set(value As String) 
     _msgsend = value 
    End Set 
End Property 

Public Sub Send() 
    SendServices.SendMessage.GetEvent(Of SendStringEvent).Publish(New SendString With {.Name = _msgsend}) 
End Sub 
End Class 

購読者:このクラスは、このポストhttp://www.shujaat.net/2010/12/wpf-eventaggregator-in-prism-40-cal.html

Public Class SendServices 
Public Shared Property SendMessage As EventAggregator 

Shared Sub New() 
    SendMessage = New EventAggregator 
End Sub 
End Class 

出版社からです:

Public Class Module2ViewModel 
Implements INotifyPropertyChanged 

Private _receivedMSG As String 
Public Property ReceivedMSG As String 
    Get 
     Return _receivedMSG 
    End Get 
    Set(value As String) 
     _receivedMSG = value 

     OnPropertyChanged("ReceivedMSG") 
    End Set 
End Property 
'Binded to subscriber View button using interactions 
Public Sub Received() 
    MsgBox(ReceivedMSG) 
End Sub 

Private Sub ReceivedMessage(msg As SendString) 
    _receivedMSG = msg.Name 
End Sub 

Public Sub New() 
    SendServices.SendMessage.GetEvent(Of SendStringEvent)().Subscribe(AddressOf ReceivedMessage, ThreadOption.UIThread, False) 
End Sub 

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged 
Protected Sub OnPropertyChanged(ByVal name As String) 
    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name)) 
End Sub 
End Class 

サブスクライバ・ビューのコードビハインド

Public Class Module2View 
    Sub New() 
     InitializeComponent() 
     Me.DataContext = New Module2ViewModel 
    End Sub 
End Class 

あなたが直接イベントを起動プロパティのセッターをバイパスされ、あなたのハンドラ内のフィールド_receivedMSGを設定しているので、あなたがOnPropertyChangedイベントを発生していないメッセージ

<TextBox Height="23" HorizontalAlignment="Left" Margin="111,39,0,0" Name="TextBox1" VerticalAlignment="Top" Width="158" Text="{Binding Path=ReceviedMSG}"/> 

答えて

1

を表示するための結合部分。

だから、代わりにプロパティのセッターを使用する必要があります。

Private Sub ReceivedMessage(msg As SendString) 
    ReceivedMSG = msg.Name 
End Sub 
+0

は、実行時のVisual Studioの[出力]ウィンドウ内の任意の結合の誤差はありますか? – nemesv

+0

none no error ..ラベルの内容をバインドするための2番目のボタンとラベル、プロパティを作成します。 ReceivedMSGを保持するために2番目のプロパティを設定するための新しいサブアイテム。期待どおりに、ラベルの内容が希望の出力に変更されました。何らかの理由でテキストボックスのテキストが更新されません。 –

+0

を試してみてください: 'Text =" {バインディングパス= ReceviedMSG、Mode = TwoWay} "'これはwpfのデフォルトであるはずです... – nemesv

関連する問題