简体   繁体   English

Windows应用商店-动态样式

[英]Windows Store - dynamic styling

I am creating a windows store application that currently loads a simple class (which loads 5 items). 我正在创建一个Windows商店应用程序,该应用程序当前加载一个简单的类(加载5个项目)。

I use a simple grid to load the items in and then set some styling; 我使用一个简单的网格加载项目,然后设置一些样式。

code snippet; 代码段;

<Grid  Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Margin="261,111,10,302">
        <ListView ItemsSource="{Binding}" Name="lstMatters" SelectionMode="Multiple">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Tapped="spMatter_Tapped" >
                        <Image Source="{StaticResource MatterImage}"></Image>
                        <GridView ItemContainerStyle="{StaticResource GridViewItemStyle1}" SelectionMode="None">
                            <GridView.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel Orientation="Horizontal" IsHitTestVisible="False"/>
                                </ItemsPanelTemplate>
                            </GridView.ItemsPanel>
                            <GridViewItem Margin="3" Style="{StaticResource gridViewHeader}" Content="FileRef: " FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Content="{Binding Path=FileRef}" FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Style="{StaticResource gridViewHeader}" Content="Description: " FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Content="{Binding Path=Description}" FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Style="{StaticResource gridViewHeader}" Content="DocumentSet: " FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Content="{Binding Path=DocumentSet}" FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Style="{StaticResource gridViewHeader}" Content="MatterType: " FontSize="20"></GridViewItem>
                            <GridViewItem Margin="3" Content="{Binding Path=MatterType}" FontSize="20"></GridViewItem>
                        </GridView>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ListView>
    </Grid>

I am trying to create a "dynamic" style in the sence that, when the DocumentSet column loads and displays in the grid, the code will do a type of "switch" statement and according to the DocumentSet, use a spesific style. 我试图创建一种“动态”样式,这样,当DocumentSet列加载并显示在网格中时,代码将执行一种“ switch”语句,并根据DocumentSet使用特殊样式。 (ie change the gridViewItem's style depending on the DocumentSet's value. (即,根据DocumentSet的值更改gridViewItem的样式。

Switch DocumentSet
Case "a"
 style = style.a
Case "b"
 style = style.b)

Hope that made sense? 希望有道理吗?

Thanks in advance. 提前致谢。

Try this video by Jerry Nixon. 尝试Jerry Nixon的这段视频。 It is basically to show how to implement interstitial ads, but you can use same concept by using the ListView.ItemTemplateSelector. 基本上是显示如何实施插页式广告,但是您可以通过使用ListView.ItemTemplateSelector使用相同的概念。

http://youtu.be/kTBdCgVVjug http://youtu.be/kTBdCgVVjug

Arun 阿伦

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM