Completed
Last Updated: 07 Jun 2023 17:05 by ADMIN
Release 5.2.0
James
Created on: 06 Jun 2023 18:43
Category: ItemsControl
Type: Bug Report
1
ItemsControl: DynamicResource Does Not Work in ItemTemplate

HI Team,

When using DynamicResource for any content inside the RadItemsControl, there are two problems:

  • If I define them in ContentPage.Resources, the RadItemsControl it does not use it at all
  • If I define them in App.Resources, the RadItemsControl will get the initial value, but not respond to any changes.

You can use the following code to verify, or use my attached demo

Resources (try them in both App.xaml and in ContentPage):

<Color x:Key="TitleTextColor">SlateBlue</Color>

 

DataTemplate

<DataTemplate x:Key="MonkeyItemTemplate">
    <Grid Padding="10">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Label Text="{Binding Name}" 
               FontAttributes="Bold" 
               TextColor="{DynamicResource TitleTextColor}" 
               Grid.Row="0" />
        <Label Grid.Row="1"
               Text="{Binding Location}"
               FontAttributes="Italic" 
               VerticalOptions="End" 
               TextColor="{DynamicResource TitleTextColor}"/>
    </Grid>
</DataTemplate>

 

View

<!-- Use CollectionView to see how it's supposed to operate -->
<CollectionView ItemsSource="{Binding Monkeys}"
                ItemTemplate="{StaticResource MonkeyItemTemplate}"
                SelectionMode="None"
                Grid.Row="0"
                Grid.Column="0"/>

<telerik:RadItemsControl ItemsSource="{Binding Monkeys}"
                         ItemTemplate="{StaticResource MonkeyItemTemplate}"
                         Grid.Row="0"
                         Grid.Column="1"
                         x:Name="ItemsControl1"/>

<Button Text="Change Colors"
        Clicked="Button_OnClicked"
        TextColor="{DynamicResource TitleTextColor}"
        BackgroundColor="{DynamicResource SubtitleTextColor}"
        Grid.Row="1"
        Grid.ColumnSpan="2"/>

 

Code-behind

private bool isChanged;

private void Button_OnClicked(object sender, EventArgs e)
{
    if (isChanged)
    {
        App.Current.Resources["TitleTextColor"] = Colors.SlateBlue;
    }
    else
    {
        App.Current.Resources["TitleTextColor"] = Colors.DarkRed;
    }

    isChanged = !isChanged;
}

 

Attached Files:
0 comments