Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply alternate row style in listbox in window phone 7

Hi I am New to Window phone 7, I have a Problem for Applying style to alternate row color in listbox in Window phone 7. Please Help Me.

like image 433
Vijay Chavda Avatar asked Jun 06 '11 04:06

Vijay Chavda


2 Answers

While WPF has an ALternationCount property that supports this, Silverlight, both the web version and WP7, do not. The easiest way to create this effect in Silverlight is to set the bacground colour of your item via a value converter. See the following thread:

Alternating background colors for ListBox rows

like image 82
ColinE Avatar answered Nov 03 '22 09:11

ColinE


private void Item_LayoutRoot_Loaded(object sender, RoutedEventArgs e)
    {

        StackPanel ItemRef = sender as StackPanel;      // get the reference to the control
        SolidColorBrush brush1 = new SolidColorBrush(Color.FromArgb(0,0,0,0));      //base colour
        SolidColorBrush brush2 = new SolidColorBrush(Color.FromArgb(255,255,0,0));  //alternate colour

        if (_useAlternate)
            ItemRef.Background = brush1;
        else
            ItemRef.Background = brush2;

        _useAlternate = !_useAlternate;
    }
like image 1
Syed Umar Ahmed Avatar answered Nov 03 '22 08:11

Syed Umar Ahmed