【问题标题】:ExpanderView does not show all ItemsExpanderView 不显示所有项目
【发布时间】:2012-03-29 16:45:04
【问题描述】:

我正在使用 WindowsPhone Toolkit 的 ExpanderView,在第一次加载时,我展开的 Expander 总是看起来像第二张图片。 看起来,它总是在所有项目的相同高度。

如果我转到另一个页面并返回,一切都会好起来的,并且布局看起来很正确 - 除了扩展器的停止线(图 1)。

this.UpdatedLayout();(当前页面) 或 ExpanderView.UpdateLayout();解决了任何事情。 未显示的项目已完全加载到该列表中。

<ItemsControl ItemsSource="{Binding EpisodeList}" Margin="20,0,0,0" Grid.Row="1" Grid.ColumnSpan="2">
<ItemsControl.ItemTemplate>
    <DataTemplate>
        <StackPanel>
            <toolkit:ExpanderView ItemsSource="{Binding Value}" >
                <toolkit:ExpanderView.Header>
                    <TextBlock Margin="0,0,10,0">
            <Run Text="Season "/>
            <Run Text="{Binding Key}" />
                    </TextBlock>
                </toolkit:ExpanderView.Header>
                <toolkit:ExpanderView.ItemTemplate>
                    <DataTemplate>
                        <Border BorderBrush="White" BorderThickness="1" Margin="5">
                            <Grid MouseLeftButtonUp="Grid_MouseLeftButtonUp">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Image Height="40"  Source="{Binding ScreenCap}" Margin="5,0,0,0"/>
                                <TextBlock x:Name="t" Margin="10" Text="{Binding Title}" TextWrapping="Wrap" Grid.Column="1" />
                            </Grid>
                        </Border>
                    </DataTemplate>
                </toolkit:ExpanderView.ItemTemplate>

            </toolkit:ExpanderView>
        </StackPanel>
    </DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

EpisodeList 是 Dictionary(int,ObservableCollection(myClass)) 的类型并实现了 INotifyPropertyChanged

如果有人有任何计划这里出了什么问题,我真的很感谢你的帮助,我只是没有在谷歌的那个列表上找到任何错误报告,也没有发现类似的错误。

(在设备和模拟器上调试)

【问题讨论】:

  • 有一次我遇到了与ExpanderView 类似的问题。它显示了 2048px 的内容Height。也许是类似的东西......

标签: windows-phone-7 silverlight-toolkit expander


【解决方案1】:

我设法通过使用列表框作为项目容器来解决这个问题,并将扩展器项目绑定到它:

                    <Controls:ExpanderView Expanded="ExpanderView_Expanded"
                        Header="{Binding}"                               
                        HeaderTemplate="{StaticResource HeaderTemplate}"                                                                             
                        NonExpandableHeader="{Binding}" 
                        ExpanderTemplate="{StaticResource ExpanderTemplate}"
                        NonExpandableHeaderTemplate="{StaticResource NonExpandableHeaderTemplate}"
                        Expander="{Binding}"
                        >
                        <ListBox ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemTemplate="{StaticResource ItemTemplate}" ItemsSource="{Binding Items}" />
                    </Controls:ExpanderView>

【讨论】:

    【解决方案2】:

    ExpanderView 也有类似的问题。我认为这可能是视图中的错误,与 2048px 限制有关。基本上,当我向展开的 ExpanderView 添加很多项目时,一切都很好,直到我折叠视图并再次展开它。展开 ExpanderView 后,除非我点击它们或滚动它,否则 2048 像素之后的任何项目都不会显示,即使这样它们也只会在它们移动时显示(项目的点击动画正在运行或列表是移动中)。

    我注意到,如果我在 ExpanderView 中添加一个项目或在展开时从中删除一个项目,那么故障就会消失,直到我下一次折叠并展开该项目,所以我快速解决了添加和删除的问题使用 ExpanderView 的 Expanded- 和 LayoutUpdated- 事件扩展视图时的虚拟项目。基本上这就是我所做的:

    • 设置状态以指示正在展开并存储正在展开的视图以供以后使用。 (在扩展事件处理程序中)
    • 等到所有 Expanderview 的布局都更新(使用 LayoutUpdated 事件处理程序来跟踪)
    • 将虚拟项目添加到展开的 ExpanderView(在 LayoutUpdated 事件处理程序中)
    • 等到所有 Expanderview 的布局都更新完毕
    • 删除虚拟项目(在 LayoutUpdated 事件处理程序中)

    也许是丑陋的解决方案,但我能想出最好的办法。希望对您的问题有所帮助。

    编辑: 对扩展器的停止线没有帮助。只是无法让那个工作..

    【讨论】:

    • 也许我只是需要一些咖啡,但我的 ExpanderView 刚刚在 Items 上获得了一个吸气剂 - 因此我将无法直接添加或删除 Item。我现在正在尝试存储和恢复 ItemsSource 数据,但这并没有改变任何东西。我正在加入 ExpandedEvent,存储发送者并添加 LayoutUpdated 事件。在 LayoutUpdated 中,我临时存储 ItemsSource,将发送者设置为空。继 Layout 将再次更新,现在我正在恢复 Itemssource 并删除 LayoutUpdated 事件
    • 澄清一点,我实际上并没有将项目直接添加到 ExpanderView 而是添加到设置为 ExpanderView 的项目源的可观察列表中。
    • 成功了!感谢这个解决方法:)
    • 还有其他方法吗?我会避免这种解决方案。
    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 2020-09-23
    • 2014-11-27
    相关资源
    最近更新 更多