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

    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>
  2. Kalin
    Admin
    Kalin avatar
    1207 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.

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top