Anatomy of the Windows 7 taskbar – TabbedThumbnail (Part 2) - Rudi Grobler
Wednesday, November 04, 2009 10:04 AM rudi

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

In my “quest” to create thumbnails similar to the once used in IE8, 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 guest by now, the TabbedThumbnailContentControl is a UI element that can host a single piece of content! The magic thou is that it will auto-magically create the TabbedThumbnail for you and show as its preview what-ever you placed inside the content control!!!

And to make it a little more useful, its 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

<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

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 showed in the taskbar! Their is also FULL integration! If you close a thumbnail in the taskbar it will be removed from the ListBox

Source

Related Posts – Anatomy of the Windows 7 taskbar series

Comments

# Anatomy of th Windows 7 Taskbar - TabbedThumbnail (Part 2)

Wednesday, November 04, 2009 10:25 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Anatomy of the Windows 7 taskbar ??? Overlays - Rudi Grobler

Pingback from  Anatomy of the Windows 7 taskbar ??? Overlays - Rudi Grobler

# Anatomy of the Windows 7 taskbar - ThumbnailToolbarButton - Rudi Grobler

Pingback from  Anatomy of the Windows 7 taskbar - ThumbnailToolbarButton - Rudi Grobler

# Make your WPF buttons color hot-track!

Sunday, November 22, 2009 2:53 PM by Rudi Grobler

One of the cool new features of the Windows 7 taskbar is that all running applications gives you this

# Anatomy of the Windows 7 taskbar – Jumplist (Part 2)

Sunday, November 22, 2009 9:07 PM by Rudi Grobler

If you application is associated with a specific file extension, then you get the last part for free

# Anatomy of the Windows 7 taskbar

Tuesday, December 08, 2009 8:36 PM by Rudi Grobler

I FINALLY managed to finish the series on all the COOL stuff in the new Windows 7 taskbar! Anatomy of