Hello,
After investigation, it was found that icons did exhibit behavior that did not update as expected when using data binding in the Shell.
Therefore, you could refer to the following steps to complete this feature using Dynamic styles.
Step 1. Add string resources in App.xaml:
<ResourceDictionary>
<x:String x:Key="Tab1IconSource">dotnet_bot.png</x:String>
<x:String x:Key="Tab2IconSource">test.png</x:String>
</ResourceDictionary>
Step 2. Set up dynamic resources for Icons in your shell:
<Tab
Title="tab1"
Icon="{DynamicResource Tab1IconSource}">
<ShellContent ContentTemplate="{DataTemplate local:MainPage}"/>
</Tab>
<Tab
Title="tab2"
Icon="{DynamicResource Tab2IconSource}">
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
</Tab>
Step 3. You need to change the value of the dynamic resource when you need to change the icon. In this example, I swapped the icons for two tabs.
var res = App.Current.Resources["Tab1IconSource"];
App.Current.Resources["Tab1IconSource"] = App.Current.Resources["Tab2IconSource"];
App.Current.Resources["Tab2IconSource"] = res;
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.