This project is read-only.

Shell.ShowView from TriggerAction or ICommand fails

Mar 1, 2012 at 2:17 PM


while digging into MVVM with Bxf and CSLA I ran into a mysterious problem.
A simple example showing the issue can be downloaded here (single VS2010 project, 300kb, libs included): 

Given a MainWindow with a MainPresenter class hosting two ContainerPanels (Region1 and Region2).
In Region1 is bound to a DependencyProperty within MainPresenter, a LoaderView with a LoaderViewModel visible.
In Region2 is bound to a DependencyProperty within MainPresender and can be a DetailView with a DetailViewModel.

On the LoaderView there is a Button which triggers an ICommand or a TriggerAction.
Within the handler inside the Command or inside the ViewModel, a new DetailView should be loaded into Region2.

When I load a DetailView from the MainPresenters constructor, is works like expected.
When I do the same from the TriggerAction Handler or from ICommand it fails.
Bxf works, the new View is instanced, and the Region2 DP is changed to the new View.
But there is no visible change within the window.

Thanks for any help.
Alexander Becker


Mar 5, 2012 at 5:08 PM

I'd put a breakpoint in the setter of the property to which the Region2 control is bound. Make sure it is actually getting set to the value you expect.

Mar 5, 2012 at 6:53 PM

I found that switching to simple properties using INotifyPropertyChanged works like expected.
So I  checked the DP declaration another time, comparing with some of these found on the web.

        public static readonly DependencyProperty Region2ContentProperty =
            DependencyProperty.Register("Region2", typeof(UserControl), typeof(MainPresenter));

        public UserControl Region2Content
            get { return (UserControl)GetValue(Region2ContentProperty); }
            set { SetValue(Region2ContentProperty, value); }

It turns out that the sting-name set when registering the DP has to be the same one from the XAML binding.
So i changed from "Region2" to "Region2Content" and it worked.

But I do not understand, why the false implementation works "half".
Instancing the detail view bound to this property from the presenters constructor worked.... 

Anyway, now it works like it should.