DeckWorkspace --> ContentControl

Aug 25, 2008 at 7:25 AM

Ex-CAB junkies may not know that the equivalent of the workhorse "DeckWorkspace" in CAL (Prism) is the ContentControl. Or so it seems to me.

The cornerstone of my Shell is:

<ContentControl x:Name="MainRegion"
   cal:RegionManager.RegionName="{x:Static f:RegionNames.MainRegion}"
   Width="Auto" Height="Auto" Margin="5"
   HorizontalAlignment="Stretch"  VerticalAlignment="Stretch"/>

Aside: the "f:" in "f:RegionNames" is an xmlns pointing to my Foundation.Interface assembly where I keep all my Region name constants ... just as we did in CAB with WorkspaceNames.

Remember to Activate the view you want to see; simply adding a view to the region will not make it appear.

Aug 29, 2008 at 6:45 PM
Actually, I would argue that a true "deck" workspace in WPF would be a custom implementation of the System.Windows.Controls.Primitives.Selector.  It would thus inherit SelectedItem, SelectionChanged, etc.  Try something like this:
public class DeckPanel : Selector
{
    static DeckPanel()
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(DeckPanel),
            new FrameworkPropertyMetadata(typeof(DeckPanel)));
    }

    protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
    {
        base.OnItemsChanged(e);
        
        if (this.SelectedIndex >= 0)
            return;

        if ((e.Action == NotifyCollectionChangedAction.Add) &&  (e.NewItems.Count > 0))
            this.SelectedItem = e.NewItems[e.NewItems.Count - 1];
        else if (this.Items.Count > 0)
            this.SelectedItem = this.Items[this.Items.Count - 1];
    }
}

<Style TargetType="{x:Type local:DeckPanel}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type local:DeckPanel}">
        <ContentPresenter Content="{TemplateBinding SelectedItem}" />
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>