Click here to Skip to main content
15,885,366 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 289K   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:local="clr-namespace:QuickZip.IO.PIDL.UserControls"
    xmlns:vm="clr-namespace:QuickZip.IO.PIDL.UserControls.ViewModel"
    xmlns:uc="http://www.quickzip.org/UserControls"
    xmlns:conv="http://www.quickzip.org/Converters"
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/QuickZip.IO.PIDL.UserControls;component/Themes/Converters.xaml" />
        <ResourceDictionary Source="Common.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <conv:IntAddConverter x:Key="iac" Add="20" />

    <!--ItemWidth="80"-->
    <uc:VirtualWrapPanelView x:Key="IconView" ColumnHeaderContainerStyle="{StaticResource ColumnHeaderContainerStyle}" 
                             ItemHeight="{Binding RelativeSource={RelativeSource AncestorType=local:FileList}, Path=ViewSize, Converter={StaticResource iac}}"
                             ItemWidth="{Binding RelativeSource={RelativeSource AncestorType=local:FileList}, Path=ViewSize, Converter={StaticResource iac}}"
                             SmallChanges="{Binding RelativeSource={RelativeSource AncestorType=local:FileList}, Path=ViewSize, Converter={StaticResource iac}}"
                             HorizontalContentAlignment="Left" >               
        <uc:VirtualWrapPanelView.ItemTemplate>
            <DataTemplate>                
                
                <StackPanel Orientation="Vertical">
                    <Image x:Name="img" HorizontalAlignment="Center" Stretch="Fill"
                           Height="{Binding RelativeSource={RelativeSource AncestorType=local:FileList}, Path=ViewSize}" 
                           Width="{Binding RelativeSource={RelativeSource AncestorType=local:FileList}, Path=ViewSize}" >
                        <Image.Source>
                            <MultiBinding Converter="{StaticResource amti}">
                                <Binding />
                                <Binding RelativeSource="{RelativeSource AncestorType=local:FileList}" Path="ViewSize" />
                            </MultiBinding >
                       </Image.Source>
                    </Image>
                    <uc:EditBox x:Name="eb" Margin="5,0" DisplayValue="{Binding EmbeddedModel.Label}" HorizontalAlignment="Center"
                        ActualValue="{Binding EmbeddedModel.Name, Mode=TwoWay}" 
                        IsEditable="{Binding EmbeddedModel.IsEditable}"        
                        IsEditing="{Binding Path=(local:FileList.IsEditing),
                                    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Mode=TwoWay}"
                        />

                </StackPanel>
            </DataTemplate>
        </uc:VirtualWrapPanelView.ItemTemplate>
        <uc:VirtualWrapPanelView.Columns>
            <GridViewColumn Width="100" Header="Name" local:FileList.SortPropertyName="sortByFullName" />
            <GridViewColumn Width="100" Header="Type" local:FileList.SortPropertyName="sortByType" />
            <GridViewColumn Width="100" Header="Time" local:FileList.SortPropertyName="sortByLastWriteTime" />
            <GridViewColumn Width="100" Header="Size" local:FileList.SortPropertyName="sortByLength" />
        </uc:VirtualWrapPanelView.Columns>
    </uc:VirtualWrapPanelView>
   
</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