8多個網格視圖我目前正在建設一個樞紐頁我的應用程序。此頁面設計爲具有多個列,每個列都有一個標題和一個GridView。但是,每個列(gridview)都填充了來自我的視圖模型的一組不同的數據。我成功地填充網格視圖,但我所看到的是,水平滾動不工作,所以我不能查看所有的樞紐頁上的信息。基本上,用戶不能水平平移。窗口樞紐頁
正在與分組數據(GridView控件),以實現這一目標的唯一途徑?
我也應該說我嘗試過使用滾動查看器,但它似乎縮小了我的GridView,它只在一列中顯示我的數據(每個gridview)。
請參考下面我目前的XAML代碼。謝謝&期待您的回覆。
<common:LayoutAwarePage
x:Name="pageRoot"
x:Class="CongressWatch.MainPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
IsTabStop="false"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CongressWatch"
xmlns:common="using:CongressWatch.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Key="AppName">congress watch</x:String>
</Page.Resources>
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<Grid Style="{StaticResource LayoutRootStyle}">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
<TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/>
</Grid>
<Grid Grid.Row="1" Margin="0,-3,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock x:Name="txtHeadingLegislators"
HorizontalAlignment="Left"
TextWrapping="Wrap"
Text="legislators"
Margin="120,0,0,20"
VerticalAlignment="Top"
Style="{StaticResource PageSubheaderTextStyle}"/>
<GridView
x:Name="grdViewLegislators"
Grid.Row="1"
Margin="120,0,0,50"
ItemsSource="{Binding Legislators, Mode=TwoWay}"
IsItemClickEnabled="True"
SelectionMode="None"
ItemClick="grdViewLegislators_ItemClick"
ItemTemplate="{StaticResource LegislatorGVDataItemTemplate}"/>
<TextBlock x:Name="txtHeadingCommittees"
Grid.Column="1"
HorizontalAlignment="Left"
TextWrapping="Wrap"
Text="committees"
Margin="80,0,0,20"
VerticalAlignment="Top"
Style="{StaticResource PageSubheaderTextStyle}"/>
<GridView
x:Name="grdViewCommittees"
Grid.Row="1"
Grid.Column="1"
Margin="80,0,0,50"
ItemsSource="{Binding Committees, Mode=TwoWay}"
IsItemClickEnabled="True"
SelectionMode="None"
ItemClick="grdViewCommittees_ItemClick"
ItemTemplate="{StaticResource CommitteeGVDataItemTemplate}"/>
<TextBlock x:Name="txtHeadingBills"
Grid.Column="2"
HorizontalAlignment="Left"
TextWrapping="Wrap"
Text="bills"
Margin="80,0,0,20"
VerticalAlignment="Top"
Style="{StaticResource PageSubheaderTextStyle}"/>
</Grid>
<VisualStateManager.VisualStateGroups>
<!-- Visual states reflect the application's view state -->
<VisualStateGroup x:Name="ApplicationViewStates">
<VisualState x:Name="FullScreenLandscape"/>
<VisualState x:Name="Filled"/>
<!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
<VisualState x:Name="FullScreenPortrait">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<!-- The back button and title have different styles when snapped -->
<VisualState x:Name="Snapped">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
嘿傑瑞德,感謝您的答覆。你提到的一切都是我的思考過程。我試圖避免創建自定義分組集合,但似乎這樣做值得花費額外的努力。這樣,我也可以遵守設計指南。我會看看你發給我的datatemplateselector鏈接。 再次感謝。 – DeleO 2012-08-14 20:14:40
沒問題。您可能想要使用「網格」模板創建一個新項目,並查看SampleDataSource.cs。在該文件內部,您將找到一個名爲SampleDataGroup的類。組只有項目,所以它不需要太複雜。在musicItems 基團=從i 組i由i.Artist成克 的OrderBy g.Key 選擇克;:基團也可以是動態使用LINQ創建 更多的信息在這裏: http://jaredbienz.wordpress.com/2012/08/01/filtering-and-grouping-listview-and-gridview-on-windows-8/ – 2012-08-15 02:09:21