Click here to Skip to main content
15,885,216 members
Articles / Desktop Programming / WPF

EXIF Compare Utility using WPF

Rate me:
Please Sign up or sign in to vote.
5.00/5 (15 votes)
12 Apr 2010CPOL8 min read 68.5K   1.1K   41  
The Exif Compare Utility is a WinDiff equivalent for image files that compares the Exif meta-data and displays the differences and similarities. The application is written using WPF and MVVM.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <LinearGradientBrush x:Key="LightBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFCDDECA" Offset="0.0"/>
                <GradientStop Color="#FF84A77C" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFB7E2AB" Offset="0.0"/>
                <GradientStop Color="#FF36B707" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="BasicBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FFA3E87D" Offset="0.0"/>
                <GradientStop Color="#FF427938" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FF427938" Offset="0.0"/>
                <GradientStop Color="#FFA3E87D" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FF082E0F" />

    <LinearGradientBrush x:Key="NormalBorderBrush" StartPoint="0,0" EndPoint="0,1">
        <GradientBrush.GradientStops>
            <GradientStopCollection>
                <GradientStop Color="#FF13480B" Offset="0.0"/>
                <GradientStop Color="#FF0B9063" Offset="1.0"/>
            </GradientStopCollection>
        </GradientBrush.GradientStops>
    </LinearGradientBrush>

    <SolidColorBrush x:Key="SolidBorderBrush" Color="#FF0B9063" />

    <SolidColorBrush x:Key="GlyphBrush" Color="#FF0B450B" />

    <ControlTemplate x:Key="ExpanderToggleButton" TargetType="ToggleButton">
        <Border Name="Border" 
                    CornerRadius="2,0,0,0"
                    Background="{StaticResource BasicBrush}"
                    BorderBrush="{StaticResource NormalBorderBrush}"
                    BorderThickness="0,0,1,0">
            <Path Name="Arrow"
                      Fill="{StaticResource GlyphBrush}"
                      HorizontalAlignment="Center"
                      VerticalAlignment="Center"
                      Data="M 0 0 L 8 8 L 16 0 Z"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="ToggleButton.IsMouseOver" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource DarkBrush}" />
            </Trigger>
            <Trigger Property="IsPressed" Value="true">
                <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
            </Trigger>
            <Trigger Property="IsChecked" Value="true">
                <Setter TargetName="Arrow" Property="Data" Value="M 0 8 L 8 0 L 16 8 Z" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="Expander">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Expander">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Name="ContentRow" Height="0"/>
                        </Grid.RowDefinitions>
                        <Border Name="Border" 
                                    Grid.Row="0" 
                                    Background="{StaticResource LightBrush}"
                                    BorderBrush="{StaticResource NormalBorderBrush}"
                                    BorderThickness="1" 
                                    CornerRadius="2,2,0,0" >
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="25" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <ToggleButton IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                                  OverridesDefaultStyle="True" 
                                                  Template="{StaticResource ExpanderToggleButton}" />
                                <ContentPresenter Grid.Column="1"
                                                      Margin="4" 
                                                      ContentSource="Header" 
                                                      RecognizesAccessKey="True" />
                            </Grid>
                        </Border>
                        <Border Name="Content" 
                                    Grid.Row="1" 
                                    Background="{StaticResource WindowBackgroundBrush}"
                                    BorderBrush="{StaticResource SolidBorderBrush}" 
                                    BorderThickness="1,0,1,1" 
                                    CornerRadius="0,0,2,2" >
                            <ContentPresenter />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Setter TargetName="ContentRow" Property="Height" Value="{Binding ElementName=Content,Path=DesiredHeight}" />
                        </Trigger>

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

    <ContextMenu x:Key="ListBoxItemContextMenu">
        <MenuItem Header="Copy" 
                  Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=DataContext.ExifCompareCopy}"
                  CommandParameter="{Binding}"/>
    </ContextMenu>

    <Style TargetType="{x:Type ListBoxItem}" x:Key="ExifListBoxItem">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
        </Style.Resources>

        <Setter Property="ContextMenu" Value="{StaticResource ListBoxItemContextMenu}" />
    </Style>
    
    <Style TargetType="{x:Type ListBox}" x:Key="ExifListBox">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="Margin" Value="10, 5, 10, 5" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <ItemsPresenter />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Items.Count}" Value="0">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <TextBlock Foreground="#FF183E11" FontSize="14">This section is empty.</TextBlock>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <DataTemplate x:Key="ExifListBoxItemTemplate">
        <Grid Background="#FF6E9A96" HorizontalAlignment="Stretch" x:Name="mainItemGrid"
              TextBlock.FontSize="15"
              MaxWidth="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}, Path=ActualWidth}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <TextBlock Text="{Binding LeftValue}" Grid.Column="0" x:Name="leftValue"
                       Padding="5" TextTrimming="CharacterEllipsis" />
            <TextBlock Text="{Binding TagName}" Grid.Column="1" x:Name="tagName"
                       Padding="5" TextTrimming="CharacterEllipsis"
                       Background="#FF3B726C" />
            <TextBlock Text="{Binding RightValue}" Grid.Column="2" x:Name="rightValue"
                       Padding="5" TextTrimming="CharacterEllipsis" />
        </Grid>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsLeftEmpty}" Value="True">
                <Setter TargetName="leftValue" Property="Opacity" Value="0.3" />
            </DataTrigger>
            <DataTrigger Binding="{Binding IsRightEmpty}" Value="True">
                <Setter TargetName="rightValue" Property="Opacity" Value="0.3" />
            </DataTrigger>

            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}, Path=IsSelected}" Value="True">
                <Setter TargetName="mainItemGrid" Property="Background" Value="#FF526C66" />
                <Setter TargetName="tagName" Property="Background" Value="#FF254843" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

</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
United States United States
Nish Nishant is a technology enthusiast from Columbus, Ohio. He has over 20 years of software industry experience in various roles including Chief Technology Officer, Senior Solution Architect, Lead Software Architect, Principal Software Engineer, and Engineering/Architecture Team Leader. Nish is a 14-time recipient of the Microsoft Visual C++ MVP Award.

Nish authored C++/CLI in Action for Manning Publications in 2005, and co-authored Extending MFC Applications with the .NET Framework for Addison Wesley in 2003. In addition, he has over 140 published technology articles on CodeProject.com and another 250+ blog articles on his WordPress blog. Nish is experienced in technology leadership, solution architecture, software architecture, cloud development (AWS and Azure), REST services, software engineering best practices, CI/CD, mentoring, and directing all stages of software development.

Nish's Technology Blog : voidnish.wordpress.com

Comments and Discussions