Need to chnage ListBox Item Color based on variable value

2 posts, 0 answers
  1. Vipul
    Vipul avatar
    1 posts
    Member since:
    Dec 2013

    Posted 13 Mar 2015 Link to this post


    I have RadListBox in windwo. Now I want to change the Item color based on the variable value then  I am using below code to do that but it is not doing whats the wrong in it? Can someone tell me or how to do like this?

                                        <Style TargetType="{x:Type telerik:RadListBoxItem}">
                                                <DataTrigger x:Name="dtCovert" Binding="{Binding iscovert}" Value="true">
                                                    <Setter Property="Foreground" Value="Blue" />

    My Control Usage
      <telerik:RadListBox SelectionMode="Extended" Grid.Row="1" Grid.Column="0" Grid.RowSpan="5" Name="listBoxAvailableList"  TabIndex="9" Width="260" Margin="2,0"  ItemsSource="{Binding AvailableCameraList}" TypedText="{Binding cameraName}" PreviewMouseDoubleClick="listBoxAvailableList_PreviewMouseDoubleClick">                             
                                    <telerik:RadListBox.ItemTemplate >
                                                    <ColumnDefinition Width="0*" />
                                                    <ColumnDefinition Width="4*" />
                                                <Label Name="lblCameraName" Grid.Column="1" Visibility="Visible" Content="{Binding Path=cameraName,Mode=TwoWay}" Width="150"></Label>
  2. Kalin
    Kalin avatar
    1283 posts

    Posted 17 Mar 2015 Link to this post

    Hello Vipul,

    In this scenario the Label used in the ItemTemplate is not inheriting the Foreground of the ListBoxItem so the trigger cannot change it. You could either bind the Foreground of the Label to the ComboBoxItem Foreground:
    <Label Name="lblCameraName" Grid.Column="1" Visibility="Visible"
            Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=telerik:RadListBoxItem}}"
            Content="{Binding Name}" Width="150"></Label>

    Or apply the same DataTrigger to the Label instead.

    Hope this helps.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top