Click here to Skip to main content
15,881,281 members
Articles / Desktop Programming / WPF

Wrap Panel Virtualization

Rate me:
Please Sign up or sign in to vote.
4.95/5 (18 votes)
2 Jan 2012CPOL2 min read 53.1K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
<UserControl x:Class="MediaAssistant.Controls.MovieDetail.MovieDetailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:Converters="clr-namespace:MediaAssistant.Converters" mc:Ignorable="d" 
             d:DesignHeight="240" d:DesignWidth="600" Background="{StaticResource BodyBackground}">
    <UserControl.Resources>
        <Converters:DoneStatusVisibilityConverter x:Key="DoneStatusVisibilityConverter" />
        <Converters:DoneStatusInverseVisibilityConverter x:Key="DoneStatusInverseVisibilityConverter" />
        <Style x:Key="LibraryItemsControlStyle" TargetType="{x:Type ItemsControl}" >
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Button Content="{Binding Title}" Style="{StaticResource LinkButtonStyle}" Margin="5,0,5,0" 
                                ToolTip="{Binding Converter={StaticResource LibraryItemSearchTooltipConverter}}"
                                Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.DataSource.SelectLibraryItemCommand}"
                                CommandParameter="{Binding}"/>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Converters:NullVisibilityConverter x:Key="NullVisibilityConverter" />
        <Converters:RecommendedMovieCountConverter x:Key="RecommendedMovieCountConverter" />
        <Converters:RatedTooltipConverter x:Key="RatedTooltipConverter" />
    </UserControl.Resources>
    <Grid>
        <DockPanel>
            <Border BorderBrush="LightGray" BorderThickness="2" DockPanel.Dock="Left" Width="160" Padding="2" Margin="2">
                <Grid>
                    <ContentControl Content="{StaticResource MoviePosterImage}"
                                    Visibility="{Binding DataSource.SelectedMovie.PosterImage, Converter={StaticResource NullVisibilityConverter}}"/>
                    <Image HorizontalAlignment="Center" VerticalAlignment="Center">
                        <Image.Source>
                            <MultiBinding Converter="{StaticResource PosterImageConverter}">
                                <Binding Path="DataSource.SelectedMovie"/>
                                <Binding Path="DataSource.SelectedMovie.Poster"/>
                                <Binding Path="DataSource.SelectedMovie.PosterImage"/>
                            </MultiBinding>
                        </Image.Source>
                    </Image>
                </Grid>
            </Border>
            <Grid>
                <TextBlock Text="Movie information is not available" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20" Foreground="Gray">
                    <TextBlock.Visibility>
                        <MultiBinding Converter="{StaticResource DoneStatusInverseVisibilityConverter}">
                           <Binding Path="DataSource.SelectedMovie"/>
                           <Binding Path="DataSource.SelectedMovie.Status"/>
                        </MultiBinding>
                    </TextBlock.Visibility>
                </TextBlock>
                <StackPanel DockPanel.Dock="Left" Margin="5">
                    <StackPanel.Visibility>
                        <MultiBinding Converter="{StaticResource DoneStatusVisibilityConverter}">
                            <Binding Path="DataSource.SelectedMovie"/>
                            <Binding Path="DataSource.SelectedMovie.Status"/>
                            <Binding Path="DataSource"/>
                        </MultiBinding>
                    </StackPanel.Visibility>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Title}" FontSize="20" FontWeight="Bold" Margin="0,5"/>
                        <TextBlock Text="-(" FontSize="20" Margin="5,5,0,5"/>
                        <Button Content="{Binding DataSource.SelectedMovie.Year}" 
                                ToolTip="{Binding DataSource.SelectedMovie.Year, Converter={StaticResource LibraryItemSearchTooltipConverter}}"
                                FontSize="20" Margin="0,5" Style="{StaticResource LinkButtonStyle}" 
                                Command="{Binding SelectYearCommand}"/>
                        <TextBlock Text=")" FontSize="20" Margin="0,5"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <Button Content="{Binding DataSource.SelectedMovie.Rated}" 
                                Style="{StaticResource LinkButtonStyle}"  
                                Margin="0,5" FontWeight="Bold"
                                Command="{Binding SelectRatedLibraryItemCommand}"
                                ToolTip="{Binding DataSource.SelectedMovie.Rated, Converter={StaticResource RatedTooltipConverter}}"
                                />
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Runtime}" Margin="10,5" Foreground="Gray"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Genres}" Style="{StaticResource LibraryItemsControlStyle}" Margin="0,5,0,5"/>
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Released, StringFormat='- {0:MMMM d, yyyy}'}" Margin="5"/>
                    </StackPanel>
                    <Border Margin="0,5" BorderThickness="1" BorderBrush="LightGray"/>
                    <StackPanel Orientation="Horizontal">
                        <ToggleButton x:Name="starButton" Width="30" Height="30" ToolTip="Mark as favorite movie"
                                      IsChecked="{Binding DataSource.SelectedMovie.IsStarred}"
                                      Style="{StaticResource opacityToggleButton}"
                                      Command="{Binding DataSource.SaveMovieStateCommand}">
                            <ContentControl Content="{StaticResource StarImage}"/>
                        </ToggleButton>
                        <ToggleButton Width="30" Height="30" Margin="10,0,0,0" ToolTip="Move to wish list"
                                      IsChecked="{Binding DataSource.SelectedMovie.IsInWishList}"
                                      Style="{StaticResource opacityToggleButton}"
                                      Command="{Binding DataSource.SaveMovieStateCommand}">
                            <ContentControl Content="{StaticResource WishListImage}"/>
                        </ToggleButton>
                        <ToggleButton Width="30" Height="30" Margin="10,0,10,0" ToolTip="Mark as watched movie"
                                      IsChecked="{Binding DataSource.SelectedMovie.Watched}"
                                      Style="{StaticResource opacityToggleButton}"
                                      Command="{Binding DataSource.SaveMovieStateCommand}">
                            <ContentControl Content="{StaticResource WatchListImage}"/>
                        </ToggleButton>
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Rating, StringFormat='Rating: {0}/10'}" FontSize="15" VerticalAlignment="Center"/>
                        <TextBlock Text="{Binding DataSource.SelectedMovie.Votes, StringFormat='Votes: {0}'}" Margin="20,0"  FontSize="15" VerticalAlignment="Center"/>
                        <Button 
                            Content="{Binding DataSource.RecommendedMovieCount, Converter={StaticResource RecommendedMovieCountConverter}}" 
                            Style="{StaticResource LinkButtonStyle}" 
                            Command="{Binding ShowRecommendedMoviesCommand}"
                            HorizontalAlignment="Right" Margin="10,5,0,0"  FontSize="15"/>
                    </StackPanel>
                    <Border Margin="0,5" BorderThickness="1" BorderBrush="LightGray"/>
                    <TextBlock Text="{Binding DataSource.SelectedMovie.Plot}" TextWrapping="Wrap"/>
                    <StackPanel Orientation="Horizontal" Margin="0,5">
                        <TextBlock Text="Director:" Margin="0,0,5,0"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Directors}" Style="{StaticResource LibraryItemsControlStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Writers:" Margin="0,0,5,0"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Writers}" Style="{StaticResource LibraryItemsControlStyle}"/>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal" Margin="0,5">
                        <TextBlock Text="Stars:" Margin="0,0,5,0"/>
                        <ItemsControl ItemsSource="{Binding DataSource.SelectedMovie.Stars}" Style="{StaticResource LibraryItemsControlStyle}"/>
                    </StackPanel>
                </StackPanel>
            </Grid>

        </DockPanel>
    </Grid>
</UserControl>

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 (Senior) KAZ Software Limited
Bangladesh Bangladesh
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions