WP7 XAML - 异常和不一致的行为

发布于 2024-12-10 15:00:37 字数 1543 浏览 0 评论 0原文

背景

在我的 XAML 中,我有一个数据模板,用于定义列表框中项目的布局。在我的模型类中,我添加了一些要绑定的属性,这些属性专门用于管理演示文稿。简而言之,我有一些按日期顺序排列的事件,每次到达新日期时,我也想包含一个标题行。因此,我有一些行定义为 Height = Auto。

问题

当它是新的一天的第一个对象时,我的属性返回数据 - 该行已填充并且一切看起来都很好。当它不是当天的第一个对象时,属性返回 null 并且该行不会出现。效果很好。大多。

但是,当我有 15 个左右的对象并向下滚动时,会出现“标题行”,但值为空(有时)。我查了很多次数据,没问题。然后,更奇怪的是,上下滚动的行为可以使其正确,或者移动发生虚假标题行的位置。所以我坚信它与我的数据无关。我认为这可能与我滚动的速度有关,但事实似乎并非如此。我的 XAML 如下 - 其中有一条注释指示标题行的定义位置。 (使用“NewDateTimeDayString”和“NewDateTimeHeaderFiller”的绑定

<StackPanel  Grid.Row="0" Grid.ColumnSpan="3">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <!--This stackpanel and the row beneath are causing issues - sometimes appearing when it should not based upon the data-->
        <!--size is auto and row is effectively dropped when there is no data-->
        <!--BUT sometimes when scrolling up and down they appear as empty -->
        <StackPanel Background="{StaticResource PhoneAccentBrush}">
            <TextBlock Grid.Row="0" Text="{Binding NewDateTimeDayString}" 
                    Style="{StaticResource PhoneTextNormalStyle}" Margin="{Binding MarginSize}" />
        </StackPanel>
        <TextBlock Text="{Binding NewDateTimeHeaderFiller}" Grid.Row="1"/>

    </Grid>
</StackPanel>

任何关于为什么会发生这种情况的想法,或者替代方法将不胜感激。非常感谢。谢谢。

Background

In my XAML I have a data template that defines the layout of items within a listbox. To my model class I have added some properties that I am binding to that are specifically for managing the presentation. In short I have some events in date order, and every time I get to a new date I want to include a heading row as well. So to so this I have some rows that are defined as Height = Auto.

Problem

When its the first object for a new day my properties return data - the row is filled and all looks good. When its not the first object for the day, the properties returns null and the row does not appear. Works well. Mostly.

But when I have say 15 or so objects and I scroll down then the 'heading rows' are appearing but with empty values (sometimes). I have checked the data numerous times and its fine. And then, even weirder, the act of scrolling up and down can make it come right, or, move the place where bogus heading lines are happening. So I firmly believe its not related to my data. I thought it may relate to how quickly I am scrolling but this does not seem to be the case. My XAML follows - There is a comment in there indicating where the heading lines are defined. (the bindings that use 'NewDateTimeDayString' and 'NewDateTimeHeaderFiller"

<StackPanel  Grid.Row="0" Grid.ColumnSpan="3">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <!--This stackpanel and the row beneath are causing issues - sometimes appearing when it should not based upon the data-->
        <!--size is auto and row is effectively dropped when there is no data-->
        <!--BUT sometimes when scrolling up and down they appear as empty -->
        <StackPanel Background="{StaticResource PhoneAccentBrush}">
            <TextBlock Grid.Row="0" Text="{Binding NewDateTimeDayString}" 
                    Style="{StaticResource PhoneTextNormalStyle}" Margin="{Binding MarginSize}" />
        </StackPanel>
        <TextBlock Text="{Binding NewDateTimeHeaderFiller}" Grid.Row="1"/>

    </Grid>
</StackPanel>

Any ideas on why this may be occurring, or an alternative approach would be appreciated. Hugely. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短叹 2024-12-17 15:00:37

与一位同事讨论了这个问题,他建议我使用绑定来更改 Stackpanel 可见性。建议这种方法可能更合适,而不是依赖于行的(自动)大小。现在已经实施了,问题已经解决。

Discussed it with a colleague who suggested that I make alter the Stackpanel visibility using a binding. Suggested that this approach might be more approproate rather than rely upon the (auto) size of a row. Have now implemented this and the problem is resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文