Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Anatomy of the Windows 7 taskbar – TabbedThumbnail (Part 2)

0.00/5 (No votes)
1 Apr 2010 1  
In my “quest” to create thumbnails similar to the ones used in Internet Explorer 8, I hit a couple of snags!

In my “quest” to create thumbnails similar to the ones used in Internet Explorer 8, I hit a couple of snags! In part 1, we looked at the basics of creating a TabbedThumbnail. This is still a very manual process, so I decided to make it more WPF-like!

Introducing TabbedThumbnailContentControl

Maybe I should take a step back and first recap what a ContentControl is in WPF?

Represents a control with a single piece of content.

http://msdn.microsoft.com/en-us/library/system.windows.controls.contentcontrol.aspx

Ok, so that isn't the greatest MSDN article every but the ContentControl is a fundamental building block of WPF… As you might have guessed by now, the TabbedThumbnailContentControl is a UI element that can host a single piece of content! The magic though is that it will auto-magically create the TabbedThumbnail for you and show as its preview whatever you placed inside the content control!!!

And to make it a little more useful, it's also fully MVVM-able! The TabbedThumbnailControl exposes 2 commands that can be bound too by the VM:

  • ActivateView - The event that occurs when a tab is activated (clicked) on the taskbar thumbnail preview.
  • CloseView - The event that occurs when a tab is closed on the taskbar thumbnail preview.

And to use the TabbedThumbnailContentControl? Very easy… Here is my view:

XML
<ListBox ItemsSource="{Binding}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <local:TabbedThumbnailContentControl Title="{Binding Title}" 
		ActivateView="{Binding ActivatedCommand}" 
		CloseView="{Binding CloseCommand}">
                <Image Source="{Binding Path}" Width="200" Height="200" />
            </local:TabbedThumbnailContentControl>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

My ViewModel:

C#
public class PhotoViewModel : WorkspaceViewModel
{
    public string Title { get; set; }
    public string Path { get; set; }

    private bool isSelected = false;
    public bool IsSelected
    {
        get { return isSelected; }
        set
        {
            if (isSelected != value)
            {
                isSelected = value;
                OnPropertyChanged("IsSelected");
            }
        }
    }

    ICommand activatedCommand;
    public ICommand ActivatedCommand
    {
        get
        {
            if (activatedCommand == null)
                activatedCommand = new DelegateCommand(Activated);

            return activatedCommand;
        }
    }

    private void Activated()
    {
        IsSelected = true;
    }
}

My VM borrowed Josh’s WorkspaceViewModel base class (to support a VM closing itself)!

And that is it! Now I can add photos to my ListBox and it would be shown in the taskbar! There is also FULL integration! If you close a thumbnail in the taskbar, it will be removed from the ListBox.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here