Click here to Skip to main content
15,891,253 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 290.1K   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:conv="clr-namespace:QuickZip.Converters"            
    xmlns:local="clr-namespace:QuickZip.UserControls"            
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Brushes.xaml" />
        <ResourceDictionary Source="pack://application:,,,/QuickZip.UserControls;component/Themes/Templates.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <ControlTemplate x:Key="BaseToggleButton" TargetType="{x:Type ToggleButton}">
        <Border x:Name="border"
                Padding="2,0"
				Background="Transparent" 
				BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="1"				
				SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition MaxHeight="11"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Rectangle x:Name="UpperHighlight" Fill="#75FFFFFF" Visibility="Collapsed"/>
                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
                              VerticalAlignment="Center" Grid.RowSpan="2" />
            </Grid>

        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsChecked" Value="False">
                <Setter TargetName="border" Property="BorderBrush" Value="Transparent" />
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="border" Property="Background" Value="{StaticResource HotTrackBrush}" />
                <Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" />
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="border" Property="Background" Value="{StaticResource PressedBrush}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


    <Geometry x:Key="ServeMan1">M4,8 L12,8 12,15 4,15 z</Geometry>
    <PathGeometry x:Key="ServeMan2">
        <PathFigure StartPoint="4,8" IsClosed="True">
            <ArcSegment Point="12,8" Size="3,3"  IsLargeArc="False"  />
            <LineSegment Point="9,8" />
            <ArcSegment Point="7,8" Size="2,2" IsLargeArc="True" />
        </PathFigure>
    </PathGeometry>

    <Style x:Key="{x:Type local:DropDownControl}" 
           TargetType="{x:Type local:DropDownControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:DropDownControl}">
                    <Grid>
                        <ToggleButton x:Name="PART_ToggleButton" Template="{StaticResource BaseToggleButton}" 
                                      BorderBrush="Silver"  
                                      IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                            <ContentPresenter Content="{TemplateBinding Header}" />
                        </ToggleButton>
                        <Popup x:Name="PART_Popup" Focusable="False"
                               IsOpen="{Binding IsDropDownOpen, Mode=TwoWay, 
                                            RelativeSource={RelativeSource TemplatedParent}}"
                               StaysOpen="False" 
                               HorizontalOffset="0"
                               VerticalOffset="0"
                               Placement="Bottom"  
                               PopupAnimation="Slide" AllowsTransparency="True">
                            <Grid x:Name="PART_DropDown">
                                <Border x:Name="PART_DropDownBorder" 
                                        Background="{DynamicResource WindowBackgroundBrush}" Padding="3"
                                        BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1">
                                    <ContentPresenter x:Name="PART_Content"  Content="{TemplateBinding Content}" />
                                </Border>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsDropDownAlignLeft" Value="True">
                            <Setter TargetName="PART_Popup" Property="HorizontalOffset"
                                    Value="{Binding ActualWidth, ElementName=PART_ToggleButton}" />
                            <Setter TargetName="PART_Popup" Property="VerticalOffset"
                                    Value="{Binding ActualHeight, ElementName=PART_ToggleButton}" />
                            <Setter TargetName="PART_Popup" Property="Placement" Value="Left" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </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