Click here to Skip to main content
15,885,546 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.2K   5.6K   41  
WrapPanel doesn't support virtualization. But we can improve the performance by simulating virtualization.
<UserControl x:Class="MediaAssistant.Controls.AlternativeLocation.AlternativeLocationView"
             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:Behavior="clr-namespace:MefBasic.Behaviors;assembly=MefBasic" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Width="700" Height="500">
    <DockPanel>
        <Border DockPanel.Dock="Top" Background="#ECECEC">
            <DockPanel>
                <TextBlock DockPanel.Dock="Top" Text="Edit title to create new movie. The new movie will be submited as a pending movie to process." Margin="5,10"/>
                <StackPanel DockPanel.Dock="Top" HorizontalAlignment="Left" Orientation="Horizontal" Height="30" Margin="0,10">
                    <Button  Width="30" Height="30" 
                             Command="{Binding DataSource.PlayMovieCommand}" 
                             CommandParameter="{Binding SelectedMovie}"
                             ToolTip="Play movie with default player"
                             Style="{StaticResource ImageButtonStyle}">
                        <ContentControl Content="{StaticResource PlayMovieImage}"/>
                    </Button>
                    <Button  Width="30" Height="30" Margin="10,0" ToolTip="Show movie in windows explorer"
                             Command="{Binding DataSource.ShowMovieInWindowsExplorerCommand}"
                             CommandParameter="{Binding SelectedMovie}"
                             Style="{StaticResource ImageButtonStyle}">
                        <ContentControl Content="{StaticResource MovieFolderImage}"/>
                    </Button>
                    <Button  Width="30" Height="30" ToolTip="Swap with default location"
                             Command="{Binding MakeDefaultLocationCommand}"
                             CommandParameter="{Binding SelectedMovie}"
                             Style="{StaticResource ImageButtonStyle}">
                        <ContentControl Content="{StaticResource DefaultImage}"/>
                    </Button>
                </StackPanel>
            </DockPanel>
            
        </Border>
        <DataGrid Name="Grid" HorizontalAlignment="Stretch" DockPanel.Dock="Top"
         CanUserAddRows="False"
         CanUserDeleteRows="False"
         CanUserSortColumns="True"
         AutoGenerateColumns="False"
         AlternatingRowBackground="{StaticResource AlternatingRowBackground}"
         RowBackground="{StaticResource RowBackground}"
         RowHeight="25"
         HorizontalGridLinesBrush="{StaticResource GridLineBrush}"
         VerticalGridLinesBrush="{StaticResource GridLineBrush}"
         ItemsSource="{Binding AlternativeMovies}"
         SelectionMode="Single"
         VirtualizingStackPanel.IsVirtualizing="True"
         VirtualizingStackPanel.VirtualizationMode="Recycling"
         EnableRowVirtualization="True"
            VerticalScrollBarVisibility="Auto"
            HorizontalScrollBarVisibility="Auto"
         Behavior:SelectionBehavior.SelectionChanged="{Binding SelectedMovieChangedCommand}"
          >
            <DataGrid.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Play" 
                              Command="{Binding DataSource.PlayMovieCommand}"
                              CommandParameter="{Binding SelectedMovie}"/>
                    <Separator/>
                    <MenuItem Header="Show in Windows Explorer" 
                              Command="{Binding DataSource.ShowMovieInWindowsExplorerCommand}"
                              CommandParameter="{Binding SelectedMovie}"/>
                </ContextMenu>
            </DataGrid.ContextMenu>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="" Width="45" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DockPanel>
                                <TextBlock Name="textBlock" DockPanel.Dock="Left" TextAlignment="Right" Width="25" Text="{Binding Index}"/>
                            </DockPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="File Name" Width="200" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Name="textBlock" Text="{Binding Path=FileName}" FontWeight="Normal" ToolTip="{Binding FullPath}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Title" Width="200">
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Title}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Name="textBlock" Text="{Binding Title}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Size" Width="80" IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Name="textBlock" Text="{Binding SizeText}" TextAlignment="Right"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</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