Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Prism 5 EventAggregator & UI

$
0
0

In a Prism 5 MVVM desktop app, I am using EventAggregator to publish data from FirstView to SecondView.  The data gets published ok, but it is not showing up in the SecondView.  This is the Model:

    public class AdrTypeMdl : INotifyPropertyChanged
    {
        public int adrtype_id { get; set; }

        private string _desc;
        public string desc
        {
            get { return _desc; }
            set
            {
                if (_desc == value)
                    return;
                _desc = value;
                NotifyPropertyChanged("desc");
            }
        }
The FirstView is a UserControl with a ListCollectionView of items (ItemsLcv).  In the FirstViewmodel, I added this in the constructor:

    ItemsLcv.CurrentChanged += new EventHandler(SelObjChanged);

And this is the corresponding SelObjChanged method in FirstViewModel:

void SelObjChanged(object sender, EventArgs e)
{
AdrTypeMdl adrType = ItemsLcv.CurrentItem as AdrTypeMdl;
if (adrType != null)
{  EventAggregator.GetEvent<SyncDetailEvent>().Publish(adrType);
}
}

Over in the SecondView, I want to display the detail record for the record selected from the FirstView.  In the SecondView,   the DataContext of the Grid is:   <Grid DataContext="SelectedObject">. 

Then this is the TextBox, also in SecondView:

<TextBox Grid.Column="1" Grid.Row="1"
    Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=Desc}"/>

All viewmodels inherit from BindableBase.  In the constructor for SecondViewModel I have:

EventAggregator.GetEvent<SyncDetailEvent>().Subscribe(HandleSyncDetailEvent); 

And then this is that method:

  public AdrTypeMdl SelectedObject { get; set; }
  public string Desc   { get; set; }

private void HandleSyncDetailEvent(object payload) { if (SelectedObject == null) { SelectedObject = (AdrTypeMdl) payload; Desc = SelectedObject.desc; }

In VS13 debugger, I can see the data being published in SecondViewModel, but nothing at all shows up in the textbox in SecondView.  What am I missing here?  How do I notify the UI?  Thank you.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>