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
- 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
1 Answer
Reset to default 1SOLUTION 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
版权声明:本文标题:using Dynamic Resource to change tintcolor in .net maui - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744944658a2633700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论