admin管理员组

文章数量:1406943

Im using DynamicResource in maui to try and change all pages properties from the settings page. it works well for button backgrounds and most other property changes but when i try to use it with Tint Color from the community toolkit it doesnt work

Tint Color to change:

<ImageButton Grid.Row="2" Grid.Column="0" BackgroundColor="{DynamicResource SecondaryColor}" CornerRadius="0" Clicked="NavigateHome" BorderWidth="2" BorderColor="Transparent" Source="profileicon.svg" Padding="5" x:Name="profileBTN">
    <ImageButton.Behaviors>
        <toolkit:IconTintColorBehavior TintColor="{DynamicResource PrimaryColor}" x:Name="profileBTNIcon"/>
    </ImageButton.Behaviors>
</ImageButton>

DynamicResource Default assignment:

<Application.Resources>
    <ResourceDictionary>
        <Color x:Key="PrimaryColor">#ff69b4</Color>
        <Color x:Key="SecondaryColor">#000000</Color>
        <Color x:Key="Tertiary">#ffffff</Color>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
            <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

method to change Colors:

private void ColorLayout1(object sender, EventArgs e)
{
    Application.Current.Resources["PrimaryColor"] = Colors.Red;
    Application.Current.Resources["SecondaryColor"] = Colors.Red;
    Application.Current.Resources["TertiaryColor"] = Colors.Red;
}

I've tried using StaticResource and setting the TintCOlor manually and that works so i don't think its an issue with the svg. So im not sure if its an issue with TintColor not allowing DynamicResource specifically or my implementation is wrong

Im using DynamicResource in maui to try and change all pages properties from the settings page. it works well for button backgrounds and most other property changes but when i try to use it with Tint Color from the community toolkit it doesnt work

Tint Color to change:

<ImageButton Grid.Row="2" Grid.Column="0" BackgroundColor="{DynamicResource SecondaryColor}" CornerRadius="0" Clicked="NavigateHome" BorderWidth="2" BorderColor="Transparent" Source="profileicon.svg" Padding="5" x:Name="profileBTN">
    <ImageButton.Behaviors>
        <toolkit:IconTintColorBehavior TintColor="{DynamicResource PrimaryColor}" x:Name="profileBTNIcon"/>
    </ImageButton.Behaviors>
</ImageButton>

DynamicResource Default assignment:

<Application.Resources>
    <ResourceDictionary>
        <Color x:Key="PrimaryColor">#ff69b4</Color>
        <Color x:Key="SecondaryColor">#000000</Color>
        <Color x:Key="Tertiary">#ffffff</Color>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
            <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

method to change Colors:

private void ColorLayout1(object sender, EventArgs e)
{
    Application.Current.Resources["PrimaryColor"] = Colors.Red;
    Application.Current.Resources["SecondaryColor"] = Colors.Red;
    Application.Current.Resources["TertiaryColor"] = Colors.Red;
}

I've tried using StaticResource and setting the TintCOlor manually and that works so i don't think its an issue with the svg. So im not sure if its an issue with TintColor not allowing DynamicResource specifically or my implementation is wrong

Share Improve this question edited Mar 30 at 13:05 Ibrahim taleb asked Mar 7 at 6:47 Ibrahim talebIbrahim taleb 474 bronze badges 2
  • This can be corraled with your bug github/CommunityToolkit/Maui/issues/957 – Yoji Commented Mar 7 at 7:12
  • Solution works on my side, you have found the solution, so you could post this as an answer. – WenyanZhang Commented Mar 26 at 2:30
Add a comment  | 

1 Answer 1

Reset to default 1

SOLUTION FOUND

instead of using the dynamic resource directly in tint color i used a 'zombie element'

<Label x:Name="Ref" BackgroundColor="{DynamicResource MyColor}" IsEnabled="False" IsVisible="False" />

and then used it as a refrence in TintColor

<toolkit:IconTintColorBehavior TintColor="{Binding Source={x:Reference Ref}, Path=BackgroundColor}" />

本文标签: using Dynamic Resource to change tintcolor in net mauiStack Overflow