英文:
How to set the background colour of searchbar in OnPlatform using dynamic resource?
问题
<SearchBar x:Name="searchBar"
Placeholder="搜索"
TextChanged="OnSearchTextChanged"
TextColor="{DynamicResource NoteTextDark}">
<SearchBar.BackgroundColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android" Value="{DynamicResource NotesEditorColor}" />
</OnPlatform>
</SearchBar.BackgroundColor>
</SearchBar>
英文:
<SearchBar x:Name="searchBar"
Placeholder="Search"
TextChanged="OnSearchTextChanged"
TextColor="{DynamicResource NoteTextDark}">
<SearchBar.BackgroundColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="Android" Value="{DynamicResource NotesEditorColor}" />
</OnPlatform>
</SearchBar.BackgroundColor>
</SearchBar>
Above code throws an invalid cast error on DynamicResource NotesEditorColor
Also, it works for DynamicResource NoteTextDark without any problem
答案1
得分: 0
if (DeviceInfo.Platform == DevicePlatform.Android)
{
searchBar.SetDynamicResource(SearchBar.BackgroundColorProperty, "NotesEditorColor");
}
英文:
if (DeviceInfo.Platform == DevicePlatform.Android)
{
searchBar.SetDynamicResource(SearchBar.BackgroundColorProperty, "NotesEditorColor");
}
Instead of the xaml, writing this in the xaml.cs code behind file worked
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论