Windows phone 7 具有不同单元格高度的WP 7列表框

Windows phone 7 具有不同单元格高度的WP 7列表框,windows-phone-7,Windows Phone 7,我正在尝试构建一个包含3种不同单元格类型的列表框。 我使用TemplateSelector进行了类型选择。 这会正确选择单元类型,但不会选择单元高度 我希望单元头为50px,其他单元类型为110px。 但标记中定义的样式将覆盖单元格高度 我尝试在网格元素中编写样式,但没有效果 有没有办法做到这一点 <delay:DeferredLoadListBox.ItemTemplate> <DataTemplate> <local:CellTempla

我正在尝试构建一个包含3种不同单元格类型的列表框。 我使用TemplateSelector进行了类型选择。 这会正确选择单元类型,但不会选择单元高度

我希望单元头为50px,其他单元类型为110px。 但标记中定义的样式将覆盖单元格高度

我尝试在网格元素中编写样式,但没有效果

有没有办法做到这一点

<delay:DeferredLoadListBox.ItemTemplate>
    <DataTemplate>
        <local:CellTemplateSelector
            Content="{Binding}">
                <local:CellTemplateSelector.CellHeader>
                    <DataTemplate>
                        <Grid
                            Name="MainGrid"
                            Width="480"
                            Height="50">
                            <Image />
                            <TextBlock />
                        </Grid>
                    </DataTemplate>
                </local:CellTemplateSelector.CellHeader>

                <local:CellTemplateSelector.GrayCell>
                    <DataTemplate>
                        <Grid
                            Name="MainGrid"
                            Width="480"
                            Height="110">
                            <Image />
                            <TextBlock />
                        </Grid>
                    </DataTemplate>
                </local:CellTemplateSelector.GrayCell>

                <local:CellTemplateSelector.WhiteCell>
                    <DataTemplate>
                        <Grid
                            Name="MainGrid"
                            Width="480"
                            Height="110">
                            <Image />
                            <TextBlock />
                        </Grid>
                    </DataTemplate>
                </local:CellTemplateSelector.WhiteCell>

        </local:CellTemplateSelector>
    </DataTemplate>
</delay:DeferredLoadListBox.ItemTemplate>

<delay:DeferredLoadListBox.Resources>
    <Style
        TargetType="ListBoxItem">
        <Setter
            Property="Height"
            Value="110" />
    </Style>
</delay:DeferredLoadListBox.Resources>

<delay:DeferredLoadListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel />
    </ItemsPanelTemplate>
</delay:DeferredLoadListBox.ItemsPanel>
</delay:DeferredLoadListBox>

我使用您的代码对此进行了测试,发现解决问题的最简单方法是从样式块中完全删除Height属性setter。如果您让DataTemplates使用您已经采用的技术来设置它们自己的高度,那么它的行为应该完全符合您的意愿


/克里斯

谢谢你的回答,克里斯。 我采用了不同的方法:

    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

   <toolkit:LongListSelector
                    x:Name="citiesListGropus"
                    Background="White"
                    ItemTemplate="{StaticResource ContentCellTemplate}"
                    GroupHeaderTemplate="{StaticResource ActualityGroupHeaderTemplate}"
                    Margin="0,66,0,0" Grid.Row="1" MouseEnter="citiesListGropus_MouseEnter" MouseLeave="citiesListGropus_MouseLeave">
xmlns:toolkit=“clr命名空间:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.toolkit”
。。。。。。。。。。。。。。。。。。。。。。

从这里开始:

ContentCellTemplate和RealityGroupHeaderTemplate是每种单元格类型的模板