Click here to Skip to main content
15,895,829 members
Articles / Web Development / HTML

WPF x FileExplorer x MVVM

Rate me:
Please Sign up or sign in to vote.
4.99/5 (52 votes)
24 Nov 2012LGPL323 min read 291K   9.4K   228  
This article describe how to construct FileExplorer controls included DirectoryTree and FileList, using Model-View-ViewModel (MVVM) pattern.
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:mvvm="http://www.quickzip.org/MVVM"
    xmlns:uc="http://www.quickzip.org/UserControls"
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Common.xaml" />
        <ResourceDictionary Source="Breadcrumb.xaml" />
        <ResourceDictionary Source="DirectoryTree.xaml" />
        <ResourceDictionary Source="FileList.xaml" />
        <ResourceDictionary Source="Navigator.xaml" />
        <ResourceDictionary Source="Statusbar.xaml" />
        <ResourceDictionary Source="Toolbar.xaml" />
        <ResourceDictionary Source="NotificationBar.xaml" />
        <ResourceDictionary Source="MediaPlayer.xaml" />

        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Converters.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Brushes.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Styles/StaticProgressBarStyle.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/UserControls/BreadcrumbItem/BreadcrumbItem.xaml" />

    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="qz_EmbedExplorer_Style" TargetType="{x:Type uc:Explorer2}">
        <Setter Property="BorderBrush" Value="{StaticResource SolidBorderBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type uc:Explorer2}">
                    <Grid TextOptions.TextFormattingMode="Display" 
                          TextOptions.TextRenderingMode="ClearType"
                          >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>                            
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <uc:Navigator2 x:Name="PART_Navigator" Grid.Row="0" Grid.Column="0" 
                                       Style="{DynamicResource qz_Navigator_Style}"                                       
                                       GoBackCommand="{Binding GoBackCommand}"
                                       GoNextCommand="{Binding GoNextCommand}"                                          
                                       Visibility="Hidden"
                                       />

                        <uc:Breadcrumb2 x:Name="PART_Breadcrumb" Grid.Row="0" 
                           DataContext="{Binding BreadcrumbViewModel}" EnableAutoFade="False"
                           Style="{DynamicResource qz_Breadcrumb_Style}" 
                           IsBreadcrumbEnabled="{Binding IsBreadcrumbEnabled, Mode=OneWay}"
                           IsLoading="{Binding DataContext.CurrentBrowserViewModel.IsLoading, 
                            RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type uc:Explorer2}}}"
                                                                                />

                        <uc:FileList2 x:Name="PART_FileList" Grid.Row="1" 
                                                  BorderBrush="{TemplateBinding BorderBrush}"
                                                  Visibility="{Binding IsDirectoryViewModel, Mode=OneWay, Converter={StaticResource btvc}}"
                                              DataContext="{Binding CurrentBrowserViewModel}"
                                              ContextMenuCommand="{Binding ContextMenuCommand}"
                                              UnSelectAllCommand="{Binding UnselectAllCommand}"
                                              RenameCommand="{Binding RenameCommand}"
                                              ViewSize="{Binding ViewSize, Mode=TwoWay}"
                                              ViewMode="{Binding ViewMode, Mode=TwoWay}"
                                              SortBy="{Binding SortBy}"
                                              SortDirection="{Binding SortDirection}"
                                              uc:FileList2.BindableSelectedItems="{Binding UISelectedItems, Mode=OneWayToSource}"
                                              uc:SelectionHelper.HighlightCount="{Binding UIHighlightCount, Mode=OneWayToSource}"
                                              uc:CommandProvider.DoubleClickCommand="{Binding ExpandCommand}"
                                              uc:CommandProvider.DoubleClickCommandParameter="{Binding}"
                                              ItemsSource="{Binding SubEntries.View}"
                                              Style="{DynamicResource qz_FileList_Style}"                                             
                                              VirtualizingStackPanel.IsVirtualizing="True" 
                                              VirtualizingStackPanel.VirtualizationMode="Recycling" />

                    </Grid>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder
Hong Kong Hong Kong

Comments and Discussions