How to modify components' textColor which defined in the ListView's TemplateCell

1 Answer 91 Views
ListView
Allen
Top achievements
Rank 1
Iron
Iron
Allen asked on 17 Aug 2022, 06:42 AM

Hey Team, 

I have a question about how to modify only parts of components' TextColor which are included in ListView's TemplateCell if we disabled ListView.

For example, I have a DataTemplate which has two parts(right side, left side) , if I disabled listview, can we only modify right side TextColor to a Color?

For below code I just want to modify Description TextColor to a Color if we disabled ListView.

                    <DataTemplate>
                        <telerik:ListViewTemplateCell>
                            <telerik:ListViewTemplateCell.View>
                                <Grid x:Name="RadDockLayout"
                                      BackgroundColor="Gray">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="152" />
                                        <ColumnDefinition Width="152" />
                                    </Grid.ColumnDefinitions>
                                    <Label HorizontalOptions="Start"
                                           Text="{Binding Name}"
                                           TextColor="White" />
                                    <Label Grid.Column="1"
                                           HorizontalOptions="End"
                                           Text="{Binding Description}"
                                           TextColor="White" />
                                </Grid>
                            </telerik:ListViewTemplateCell.View>
                        </telerik:ListViewTemplateCell>
                    </DataTemplate>

 

Thanks

Allen

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 18 Aug 2022, 07:43 AM

Hello Allen,

You can use the DataTrigger approach to change the color of the disabled Label Text. 

Example:

 

<telerik:ListViewTemplateCell.View>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <HorizontalStackLayout Margin="10, 10, 10, 0">
                                    <Label Text="{Binding Title}" 
                                           IsEnabled="{Binding IsFavourite}"
                                           TextColor="Blue"
                                       FontSize="16" VerticalOptions="Center">
                                        <Label.Triggers>
                                            <DataTrigger Binding="{Binding IsFavourite}"
                                         TargetType="Label"
                                         Value="False">
                                                <Setter Property="TextColor" Value="LightGray" />
                                            </DataTrigger>
                                        </Label.Triggers>
                                    </Label>
                                </HorizontalStackLayout>
                                <HorizontalStackLayout Grid.Row="1" Margin="10, 0, 10, 10">
                                    <Label Text="{Binding Author}" FontSize="13" FontAttributes="Italic" TextColor="Gray" />
                                </HorizontalStackLayout>
                            </Grid>
                        </telerik:ListViewTemplateCell.View>

Regards,
Didi
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Tags
ListView
Asked by
Allen
Top achievements
Rank 1
Iron
Iron
Answers by
Didi
Telerik team
Share this question
or