none
关于XAML布局中多个固定长宽的StackPanel的滚动条问题 RRS feed

  • 问题

  • 各位好,我程序需要显示某个目录下的文件夹与文件,所以我设置了两个stackPanel显示它们,因为文件数量上万个,所以我固定了文件GridView的大小(不然不能UI虚拟化导致占用内存太大),但是固定后,页面就出现两个滚动条了,请问有没有大神知道,我要如何操作才能使只显示一条滚动条并且能拖动就能滚动文件夹与文件呢?我现在的程序只能滚动文件夹或者文件,呜呜呜~~~ 

        <Page.Resources>
    
            <CollectionViewSource
                x:Name="DirItemsViewSource"
                Source="{Binding DirItems}"
                />
            <CollectionViewSource
                x:Name="FileItemsViewSource"
                Source="{Binding FileItems}"
                />
            
            <!-- 文件缩略图模式 -->
            <DataTemplate x:Key="FileThumbnailView">
                <Grid Background="White" HorizontalAlignment="Left" Width="120" Height="120">
            
                    <Border  Background="White">
                        <Image Margin="0" 
                               Source="{Binding TbImage}" Stretch="UniformToFill" />
                    </Border>
                </Grid>
            </DataTemplate>
            <ItemsPanelTemplate x:Key="FileThumbnailViewPanel">
                <WrapGrid Orientation="Vertical" MaximumRowsOrColumns="4"/>
            </ItemsPanelTemplate>
    
            <!-- 文件夹缩略图模式 -->
            <DataTemplate x:Key="DirThumbnailView">
                <Canvas Background="#7425d0" HorizontalAlignment="Left" Width="258" Height="120">
                    <TextBlock Width="228" Height="25" TextAlignment="Right" TextTrimming="WordEllipsis"  Canvas.ZIndex="0" Canvas.Left="15" Canvas.Top="90" Text="{Binding FolderName}" FontSize="19" FontFamily="Fonts/Fonts.zip#Microsoft YaHei"/>
                </Canvas>
            </DataTemplate>
            <ItemsPanelTemplate x:Key="DirThumbnailViewPanel">
                <WrapGrid Orientation="Vertical" MaximumRowsOrColumns="4"/>
            </ItemsPanelTemplate>
    
        </Page.Resources>
        
        <Grid Background="White">
            <Grid.RowDefinitions>
                <RowDefinition Height="54"></RowDefinition>
                <RowDefinition Height="27*"></RowDefinition>
                <RowDefinition Height="13*"/>
                <RowDefinition Height="286*"/>
                <RowDefinition Height="31*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="130"/>
                <ColumnDefinition Width="83*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="335"/>
            </Grid.ColumnDefinitions>
            
            <ScrollViewer
                Grid.Column="0" 
                Grid.Row="3" 
                Grid.ColumnSpan="4" 
                Grid.RowSpan="2"
                HorizontalScrollBarVisibility="Auto"
                VerticalScrollBarVisibility="Disabled"
                HorizontalScrollMode="Enabled"
                VerticalScrollMode="Disabled"
                ZoomMode="Disabled"
                Margin="0,20,0,0">
    
                <StackPanel  
                VerticalAlignment="Top" 
                HorizontalAlignment="Left"
                Orientation="Horizontal"
                >
    
                    <!-- 文件夹面板 -->
                    <StackPanel x:Name="m_folderStackPanel"  Margin="130,0,20,0">
                        <GridView 
                        x:Name="m_folderGridView" 
                        ItemsSource="{Binding Source={StaticResource DirItemsViewSource}, Mode=TwoWay}" 
                        ItemTemplate="{StaticResource DirThumbnailView}"
                        ItemsPanel="{StaticResource DirThumbnailViewPanel}"
                        TabIndex="1"
                        SelectionMode="Multiple"
                        IsSwipeEnabled="True"
                        CanDragItems="False" >
                        </GridView>
                    </StackPanel>
    
                    <!-- 文件面板 -->
                    <StackPanel x:Name="m_fileStackPanel"  Margin="20,0,0,0">
                        <GridView 
                        x:Name="m_fileGridView" 
                        ItemsSource="{Binding Source={StaticResource FileItemsViewSource},  Mode=TwoWay}"
                        ItemTemplate="{StaticResource FileThumbnailView}"
                        ItemsPanel="{StaticResource FileThumbnailViewPanel}"
                        Width="1200"
                        Height="700"
                        TabIndex="1"
                        SelectionMode="Multiple"
                        IsSwipeEnabled="True"
                        CanDragItems="False">
                            
                        </GridView>
    
                    </StackPanel>
                </StackPanel>
            </ScrollViewer>
        </Grid>

    MainPage::MainPage()
    {
    	InitializeComponent();
    	Platform::Collections::Vector<ItemViewBinding^>^ folderItemVec=ref new Vector<ItemViewBinding^>();
    	Platform::Collections::Vector<ItemViewBinding^>^ imageItemVec=ref new Vector<ItemViewBinding^>();
    
    	for (int i = 0; i < 5; i++)
    	{
    		folderItemVec->Append(ref new ItemViewBinding("我的文件",nullptr));
    	}
    
    	StorageFolder ^localFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;
    	String ^imgPath = localFolder->Path+"\\Assets\\JPG.png";
    	Windows::UI::Xaml::Media::ImageSource^ tbImg = nullptr;
    	tbImg= ref new Imaging::BitmapImage(ref new Uri(imgPath));
    	for (int i = 0; i < 5000; i++)
    	{
    		imageItemVec->Append(ref new ItemViewBinding("",tbImg));
    	}
    	
    	m_folderGridView->ItemsSource = folderItemVec;
    	m_fileGridView->ItemsSource = imageItemVec;
    }

      
    2014年1月15日 7:04

全部回复