RegionManager binds Views or ViewModels?

Topics: Prism v2 - Silverlight 3, Prism v2 - WPF 3.5
Aug 5, 2009 at 7:10 PM
Edited Aug 5, 2009 at 7:13 PM

I've been able to get quite far along with my Multi-Target application by following the guidance, and am liking what I see so far. I started out with a Silverlight only app, and the WPF version required a lot less tweaking than I thought it would. Almost everything is shared between the two apps except for the views, styles, templates, etc. However, there's one thing I find confusing and can't get my head around.

If you refer to the StockTraderRI reference, there's an AnimatedTabControl used as a region in both the SL and WPF apps. The (shared) modules register two views in that region (PositionSummaryView and WatchListView). In SL, there's a CustomTabItemTemplate for displaying the TabItem, in WPF there's an equivalent ShellTabItemStyle that defines the ControlTemplate for the TabItem.

What's confusing me is why, in the case of WPF, the template seems to be binding to the model via the DataContext of the VIEW (I'd expect to have to do this):

<Setter Property="Header" Value="{Binding Content.DataContext.HeaderInfo, RelativeSource={RelativeSource Self}}" >

Whereas in SL the template seems to be binding to the MODEL:



<TextBlock x:Name="textBlock" Text="{Binding Path=HeaderInfo}" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Trebuchet MS" FontSize="14" Foreground="#FFFFFFFF" Margin="13,5,13,5" Cursor="Hand" />

How is the SL template able to bind directly to the Model?

Aug 5, 2009 at 7:40 PM
Edited Aug 5, 2009 at 8:04 PM

I think I see what's happening. In SL the TabControlRegionAdapter.TabControlRegionSyncBehaviour.GetDataContext() is setting the DataContext of the TabItem to the DataContext of the View, rather than the View itself. This is inconsistent with the WPF approach, which doesn't have a similar adapter, and simply binds the View to the TabItem.

Aug 6, 2009 at 2:34 AM
Edited Aug 6, 2009 at 2:34 AM

OK, so for experimental purposes I changed the TabControlRegionAdapter.TabControlRegionSyncBehaviour.GetDataContext() to return the View (FrameworkElement) instead of the Model (FrameworkElement.DataContext), and the StockTraderRI still seems to work just fine in SL. I take it that the restriction on not being able to use a FrameworkElement as a DataContext was removed between SL2 and SL3?

Anyone know for sure?