This is a migrated thread and some comments may be shown as answers.

Need to chnage ListBox Item Color based on variable value

1 Answer 178 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Vipul
Top achievements
Rank 1
Vipul asked on 13 Mar 2015, 05:16 PM
Hi,

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 anything..so whats the wrong in it? Can someone tell me or how to do like this?

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


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 >
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="0*" />
                                                <ColumnDefinition Width="4*" />
                                            </Grid.ColumnDefinitions>
                                            <Label Name="lblCameraName" Grid.Column="1" Visibility="Visible" Content="{Binding Path=cameraName,Mode=TwoWay}" Width="150"></Label>
                                        </Grid>
                                    </DataTemplate>
                                </telerik:RadListBox.ItemTemplate>
                            </telerik:RadListBox>

1 Answer, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 17 Mar 2015, 11:41 AM
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.

Regards,
Kalin
Telerik
 

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.

 
Tags
ListBox
Asked by
Vipul
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or