在VisualState中更改GridView GroupStyle [英] Change GridView GroupStyle in VisualState

查看:109
本文介绍了在VisualState中更改GridView GroupStyle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Windows 8.1 WinRT / XAML应用程序中,我有一个分组 GridView 和相应的 GroupStyle

 < GridView ItemsSource ={Binding Source = {StaticResource groupedViewSource}}> 
...
< GridView.GroupStyle>
< GroupStyle>
< GroupStyle.HeaderTemplate>
< DataTemplate>
...
< / DataTemplate>
< GroupStyle.Panel>
< ItemsPanelTemplate>
< VariableSizedWrapGrid
Style ={StaticResource NormalWrapGridStyle}/>
< / ItemsPanelTemplate>
< / GroupStyle>
< /GridView.GroupStyle>
< / GridView>

现在这是全屏视图的版本。我想要的是调整GridView的UI以获得更小的显示宽度,例如在肖像模式下。因此,我想调整 GroupStyle.HeaderTemplate 用于较小的标题,而 GroupStyle.Panel 用于较少的单个GridView组的边距。

通常我使用不同的VisualState进行这种UI自适应,但似乎无法设置不同的 GroupStyle 在VisualState中或更改相应的模板。任何建议?

解决方案

我在这一个上与@Zubair。如果您可以为每个方向制作多个布局,则总体上会有更好的解决方案。如果你喜欢,你可以将它们抽象为用户控件。如果你喜欢,你可以重用数据模板。但是,在单一布局中处理方向和监视器缩放是不必要的过度复杂性。


阅读: http://blog.jerrynixon.com/2013/12/the-two-ways-to-handle-orientation-in.html


如果您必须按照您的意愿去做,我不建议您这样做,您可以看看这个解决方案: http://xaml.codeplex.com/SourceControl /latest#MVA/201311_Blend/XamlSpace/ViewModels/MainPageViewModel.cs 如果您愿意,可以下载整个项目。再次,这不是我会做的。


In my Windows 8.1 WinRT/XAML app I have a grouped GridView with a corresponding GroupStyle:

<GridView ItemsSource="{Binding Source={StaticResource groupedViewSource}}">
    ...
    <GridView.GroupStyle>
        <GroupStyle>
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    ...
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
            <GroupStyle.Panel>
                <ItemsPanelTemplate>
                    <VariableSizedWrapGrid 
                         Style="{StaticResource NormalWrapGridStyle}" />
                </ItemsPanelTemplate>
            </GroupStyle.Panel>
        </GroupStyle>
    </GridView.GroupStyle>
</GridView>

Now this is the version for a fullscreen view. What I want is to adapt the UI of the GridView for smaller display widths, e.g. in Portrait mode. Thus I want to adapt the GroupStyle.HeaderTemplate for smaller headers and the GroupStyle.Panel for less margin around single GridView groups.

Normally I'm doing such UI adaptions using a different VisualState, but it seems not to be possible to set a different GroupStyle in a VisualState or to change the according templates. Any suggestions?

解决方案

I am with @Zubair on this one. If you can make multiple layouts for each orientation you have a better solution overall. You can abstract them into user controls if you like. You can reuse the data templates if you like. But handling both orientation AND monitor scaling in a single layout is a needless over-complexity.

Read this: http://blog.jerrynixon.com/2013/12/the-two-ways-to-handle-orientation-in.html

If you must do it like you are wanting, which I do not recommend, you might look at this solution: http://xaml.codeplex.com/SourceControl/latest#MVA/201311_Blend/XamlSpace/ViewModels/MainPageViewModel.cs You can download the whole project if you like. Again, it's not what I would do.

这篇关于在VisualState中更改GridView GroupStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆