Click here to Skip to main content
15,892,298 members
Articles / Web Development / HTML

My Personal Commander Variant

Rate me:
Please Sign up or sign in to vote.
4.66/5 (13 votes)
5 Oct 2016CPOL14 min read 44.6K   1.2K   47  
A C#/WPF application for displaying folders on a grid and performing combined functions on them.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <LinearGradientBrush x:Key="Brush_HeaderBackground" StartPoint="0.5,0" EndPoint="0.5,1">
        <GradientStop Color="#66000088" Offset="0" />
        <GradientStop Color="#BB000088" Offset="1" />
    </LinearGradientBrush>

    <DataTemplate x:Key="HCCHeader">
        <Border 
            BorderBrush="LightGray" 
            BorderThickness="1" 
            CornerRadius="5" 
            Margin="3" 
            Padding="4" 
            SnapsToDevicePixels="True"
            Background="{Binding RelativeSource={RelativeSource AncestorType=HeaderedContentControl}, Path=Background}"
            >
            <TextBlock 
                    FontSize="14"
                    FontWeight="Bold"
                    Foreground="{Binding RelativeSource={RelativeSource AncestorType=HeaderedContentControl}, Path=Foreground}" 
                    HorizontalAlignment="Center"
                    Text="{Binding}"
                    />
        </Border>
    </DataTemplate>

    <!-- Once this style is applied, it is not possible any longer to 
        use the ContentHeaderTemplate of the HeaderedContentControl. Why? -->
    <Style x:Key="FolderBrowserHCCStyle" TargetType="{x:Type HeaderedContentControl}">
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="HeaderTemplate" Value="{StaticResource HCCHeader}"/>
        <Setter Property="Template">
            <Setter.Value>
                <!-- 
                This template ensures that content of a HeaderedContentControl 
                fills the available vertical space. 
                -->
                <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
                    <DockPanel>
                        <ContentPresenter 
                              DockPanel.Dock="Top"
                              ContentSource="Header" 
                              ContentTemplate="{TemplateBinding HeaderTemplate}" 
                              />
                        <ContentPresenter 
                              ContentSource="Content" 
                              ContentTemplate="{TemplateBinding ContentTemplate}" 
                              />
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- Properties are placed as HeaderedContentControls of a certain Header>Left/Content>Right style -->
    <Style x:Key="PropertiesHCCStyle" TargetType="{x:Type HeaderedContentControl}">
        <Setter Property="IsTabStop" Value="False" />

        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <Label Content="{Binding}"/>
                </DataTemplate>
            </Setter.Value>
        </Setter>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type HeaderedContentControl}">
                    <DockPanel Margin="2,1,2,1">
                        <ContentPresenter 
                            Width="150"
                            DockPanel.Dock="Left"
                            ContentSource="Header" 
                            ContentTemplate="{TemplateBinding HeaderTemplate}" 
                            />
                        <ContentPresenter 
                            ContentSource="Content" 
                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                            />
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- see http://stackoverflow.com/questions/1753803/wpf-listbox-trigger-not-working-for-isfocused-property -->
    <Style x:Key="FocusedBorder" TargetType="Control">
        <Style.Setters>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <SolidColorBrush Color="LightGray"/>
                </Setter.Value>
            </Setter>
        </Style.Setters>
        <Style.Triggers>
            <EventTrigger RoutedEvent="GotFocus">
                <BeginStoryboard>
                    <Storyboard>
                        <ThicknessAnimation
                            Storyboard.TargetProperty="BorderThickness"
                            Duration="0" FillBehavior="HoldEnd" From="1" To="3" />
                        <ColorAnimation 
                            Storyboard.TargetProperty="BorderBrush.Color"
                            Duration="0" FillBehavior="HoldEnd" From="LightGray" To="Red" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
            <EventTrigger RoutedEvent="LostFocus">
                <BeginStoryboard>
                    <Storyboard>
                        <ThicknessAnimation
                            Storyboard.TargetProperty="BorderThickness"
                            Duration="0" FillBehavior="HoldEnd" From="3" To="1" />
                        <ColorAnimation 
                            Storyboard.TargetProperty="BorderBrush.Color"
                            Duration="0" FillBehavior="HoldEnd" From="Red" To="LightGray" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Style.Triggers>
    </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 Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions