简体   繁体   中英

WP7 XAML - unusual and inconsistent behaviour

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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