Notification not triggered when navigating to view ...

Topics: Prism v4 - Silverlight 4
Mar 28, 2013 at 5:43 AM
Dear Friends.

I have been workng on PRISM for a whle, I have done a working basic things .. now it comes to a seruios one, where I need to develop a dependable running application.

So, I have a view that show or hide controls based on user selection also some combos should show values different based on that selection, I have implemented this through a viewmodel properity, this properity get it's values from CurrentRecord class.
My view controls are binded to CurrentRecord as follows:
{Binding Path=__CurrentRecord.Name__, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnException=True}" Visiability={Binding Path=ShowInd", Mode=TwoWay,Converter={StaticResource booltovisability}}"
On the OnNavigatedTo event of this view, I create a new CurrentRecord class with default properities, but that doesn't trigger the controls visability unless I switch the value again by screen selection.

Please be aware that my viewmodel is implementing the NotificationObject and CurrentRecord is as follows:
private masterFile _currentRecord;
public masterFile CurrentRecord
   get{ return _currentRecord;}
   set { _currentRecord = value; RaiseProperityChanged(()=> CurrentRecord);}
and I change the ShowInd based on the value on CurrentRecord by subscribing to ProperityChanged event

Appreciated If anyone can help.
Best regards
Apr 3, 2013 at 5:27 PM

Based on the code snippets you provided, we couldn't find anything wrong in your code. Therefore, we think that the problem could be related on the way you are subscribing and raising the property changed event on the ShowInd property. It would be helpful if you could provide us a code snippet showing this property logic so that we can analyze it in further detail.


Federico Martinez
Apr 4, 2013 at 7:55 PM
Dear Federico,

Appreciate your reply, I got this resolved thanks, I belive I have aproblem with the navigation right now.

I am loading a view using RequestNavigation as follows:
RegionManager.RequestNavigate(RegionNames.TDetailsRegion, new Uri(builder.ToString(), UriKind.Relative));
and I am removing the views from it's viewmodel as follows when back button is pressed as follows:
private void GoBack()
            if (CanClose)
                foreach (var region in RegionManager.Regions)
                    foreach (var view in region.Views)
                        if (view is TDetailsView)
                            if (((TDetailsView)view).DataContext == this)
                                region.Context = null;
                                // region.Remove(view);
                                // ((TaxpayerDetailsView) view).DataContext = null;
the problem is when I try to navigate again to that view using the code above, I got the view loaded but not it's viewmodel.
What could be the problem.

I try to use implement the in the viewmodel and use the deactivate instead, and I got an error says "Deactivated is not allowed in this type of view"

If you could help on that issue will be great.

Thanks again & best regards
Apr 5, 2013 at 4:48 PM

Based on my understanding, the problems you are facing could be related to the following causes:
  • The error related to region.Deactivate(view) is due to the fact that you are probably trying to deactivate a view inside an ItemsControl region or one of its derived classes. Instead of trying to deactivate the view, please use region.Remove(view).
  • Related to the lack of ViewModel, I see that you have ((TaxpayerDetailsView) view).DataContext = null in your code. If this line is executing, and your view is a singleton, when you try to navigate to it again the container will provide you the same instance that you just removed. This instance will not have a view model as you cleared its DataContext property (and properties are only populated by the container when a new instance is created). If this is case, you can solve this by exporting the view as a non-singleton type or by removing the aforementioned line.
Hope this helps,

Federico Martinez