Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / WPF

WPF Book Reader

Rate me:
Please Sign up or sign in to vote.
4.29/5 (16 votes)
10 May 2012GPL35 min read 110.9K   120  
A WPF book reader for cbz/cbr files
<Window x:Class="BookReader.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ucc="clr-namespace:BookReader"    
    xmlns:local="clr-namespace:BookReader"
    Title="Book Reader" Height="400" Width="800" Loaded="Window_Loaded" WindowStyle="SingleBorderWindow" WindowState="Normal" 
        Closing="Window_Closing">
    <Grid Name="MainGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ToolBar Height="36" Margin="-3,0,0,0">
            <Button Name="btnOpen" HorizontalAlignment="Stretch" Click="btnOpen_Click" Width="30" Margin="5,0,0,0" ToolTip="Open a book everywhere on your disks">
                <Image Source="Resources\open_folder.png"></Image>
            </Button>
            <Button Name="btnFullScreen" HorizontalAlignment="Stretch" Click="btnFullScreen_Click" Width="30" Margin="5,0,0,0" ToolTip="Put Book Reader in full screen mode and hide explorers">
                <Image Source="Resources\ecran.png"></Image>
            </Button>
            <Button Name="btnRefresh" HorizontalAlignment="Stretch" Click="btnRefresh_Click" Width="30" Margin="5,0,5,0" ToolTip="Refresh the catalog by a full scan of the folder">
                <Image Source="Resources\refresh.png"></Image>
            </Button>
            <Button Name="btnOptions" Width="30" Click="btnOptions_Click" ToolTip="Display the options dialog" >
                    <Image Source="Resources\tools.png"></Image>
            </Button>
            <Separator Width="3"></Separator>
            <Button Name="bntQuit" HorizontalAlignment="Stretch" Click="btnQuit_Click" Width="30" Margin="5,0,0,0" ToolTip="Close Book Reader">
                <Image Source="Resources\exit.png"></Image>
            </Button>
            <Button Name="bntAbout" Click="btnAbout_Click" Width="30" Margin="5,0,5,0" ToolTip="About the author and Acknowlegdments">
                <Image Source="Resources\info.png"></Image>
            </Button>
            <Separator Width="3"></Separator>
            <Button Name="bntFitWidth" Click="btnFitWidth_Click" Width="30" Margin="5,0,0,0" ToolTip="Fit the display to the page width">
                <Image Source="Resources\FitWidth.png"></Image>
            </Button>
            <Button Name="bntFitHeight" Click="btnFitHeight_Click" Width="30" Margin="5,0,5,0" ToolTip="Fit the display to the page height">
                <Image Source="Resources\FitHeight.png"></Image>
            </Button>
            <Separator Width="3"></Separator>
            <Button Name="bntConvertPDF" Width="30" Margin="5,0,5,0" ToolTip="Convert a PDF to CBZ/CBR" Click="bntConvertPDF_Click">
                <Image Source="Resources\acroread.png"></Image>
            </Button>
            <Separator Width="3"></Separator>
            <Slider Name="zoomSlider" Minimum="1" Maximum="400" SmallChange="1" TickPlacement="None"
                    Value="100" Width="200" VerticalAlignment="Center" ValueChanged="Slider_ValueChanged"
                    LargeChange="10" IsSnapToTickEnabled="True" Focusable="False"></Slider>
            <Label Name="zoomPercent" Margin="5,0,0,0" VerticalAlignment="Center" Content="{Binding ElementName=zoomSlider, Path=Value}"></Label>
            <Label Margin="5,0,0,0" VerticalAlignment="Center">%</Label>
            <Separator Width="3"></Separator>
            <Label Name="Info" VerticalAlignment="Center" HorizontalAlignment="Stretch" IsHitTestVisible="False" Margin="5,0,0,0" ToolTip="Get information about the image cache">No cache info available</Label>
            <Separator Width="3"></Separator>
            <Label Name="PageInfo" VerticalAlignment="Center" HorizontalAlignment="Stretch" IsHitTestVisible="False" Margin="5,0,0,0" ToolTip="Display the current page displayed">No displayed page</Label>
        </ToolBar>
        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200"/>
                <ColumnDefinition Width="20"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
        <ListBox Grid.Column="0" BorderThickness="0"
              VirtualizingStackPanel.IsVirtualizing="True"
              IsSynchronizedWithCurrentItem="True"
              Name="CatalogListBox" 
              SelectionMode="Single" 
              ItemsSource="{Binding}" 
              SelectedIndex="0"
              Style="{DynamicResource CatalogCoverStyle}"
                >
        <ListBox.ContextMenu>
            <ContextMenu>
                <MenuItem Header="Read" Click="MenuItem_Load" />
                <MenuItem Header="Set bookmark" Click="MenuItem_BookMark"/>
                <MenuItem Header="Goto bookmark" Click="MenuItem_GotoBookMark"
                         Visibility="{Binding Path=Bookmark, Converter={StaticResource BookmarkToVisibilityConverter}}"/>
                <MenuItem Header="Clear bookmark" Click="MenuItem_ClearBookMark"
                         Visibility="{Binding Path=Bookmark, Converter={StaticResource BookmarkToVisibilityConverter}}"/>
            </ContextMenu>
        </ListBox.ContextMenu>
        </ListBox>
        <ucc:GridSplitterExpander Grid.Column="1" Orientation="Vertical" Title="Catalog's covers" GridIndex="0" 
            x:Name="Splitter" Background="{DynamicResource ControlBackgroundBrush}"/>
        <local:PageViewer x:Name="SimplePageView" Grid.Column="2" 
                          PageChanged="SimplePageView_PageChanged"
                          ZoomChanged="SimplePageView_ZoomChanged" />
        </Grid>
    </Grid>
</Window>

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 General Public License (GPLv3)


Written By
Architect
France France
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside

https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/

Comments and Discussions