Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone ListBox Item Background Changing Color Even Though It's Set Explicitely

I am looking for 1) what is going on, and 2) how to fix the issue.

Issue

If a ListBox Item height is above 2521, it seems to change the background to black even when the background is explicitly set to something else.

How To Reproduce

Take the sample XAML file I have below, and in your xaml.cs file add the following:

DataContext = new List<int>() { 1 };

Change the height of the TextBlock to 2522 or higher.

The sample code is not where I encountered the issue, however it is a simple example to demonstrate the bug. I am not planning on having a TextBlock that is 2522+ in size :)

Sample XAML file

    <Grid x:Name="LayoutRoot" Background="Brown">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <phone:Pivot x:Name="pivot" Title="{Binding name}" Grid.Row="1" Foreground="White" Margin="10,0,0,0">
            <phone:PivotItem x:Name="mainPivot" Header="menu" Margin="0,0,20,0">
                <ListBox ItemsSource="{Binding}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Background="White">
                                <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                                    <TextBlock Height="2521" Text="some data" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}" FontSize="22" Foreground="Purple"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </phone:PivotItem>

        </phone:Pivot>

    </Grid>
</phone:PhoneApplicationPage>

Remarks

A few people have raised concerns about my UI. The above code is a sample and not my actual UI. There are no performance issues and the ListBox is not sluggish. Everything works as expected except the background changes color.

like image 221
Coltin Avatar asked Nov 13 '22 17:11

Coltin


1 Answers

In WP7 TextBlocks had a height limit of 2048x2048. I'm not sure if that was fixed in WP8 or not, but it seems like the same issue you're hitting right now. Consider splitting up text to chunks smaller than 2048 pixels or using something that does that for you like ScrollableTextBlock.

like image 84
JustinAngel Avatar answered Dec 08 '22 00:12

JustinAngel