如何更改xamarin表单UWP中listview激活的颜色

时间:2017-05-17 06:05:25

标签: xamarin uwp xamarin.forms uwp-xaml xamarin.uwp

我想在Xamarin Forms - UWP中单击ListView项目时更改突出显示的颜色。在android我设置样式来解决这个问题。async saveFavorite() { // loadFavorite() here, // make sure you've got data "your_new_JSON_data" which has been converted into object, then maybe: "your_new_JSON_data.push({NEW_OBJ})"; // after that, SAVE NEW DATA now: try { await AsyncStorage.setItem("@PROJECT_NAME:your_favorite_array", JSON.stringify(your_new_JSON_data)); // same here, if you use flux or redux here, you can save the new data here: // FavoriteActionCreators.set_favorite(your_new_JSON_data); } catch (error) { console.log('AsyncStorage error: ' + error.message); } } 我如何实现同样的目标是UWP。添加的图片:http://imgur.com/a/pFlNi

2 个答案:

答案 0 :(得分:1)

导航到您的UWP项目,打开您的App.xaml,并放置以下内容:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">

<!--Your accent color-->
<Color x:Key="SystemAccentColor">#FF055ADA</Color>                

<SolidColorBrush x:Key="SystemControlHighlightAltListAccentHighBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.9" />
<SolidColorBrush x:Key="SystemControlHighlightAltListAccentLowBrush" Color="ThemeResource SystemAccentColor}" Opacity="0.6" />
<SolidColorBrush x:Key="SystemControlHighlightAltListAccentMediumBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.8" />
<SolidColorBrush x:Key="SystemControlHighlightListAccentHighBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.9" />
<SolidColorBrush x:Key="SystemControlHighlightListAccentLowBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.6" />
<SolidColorBrush x:Key="SystemControlHighlightListAccentMediumBrush" Color="{ThemeResource SystemAccentColor}" Opacity="0.8" />

    </ResourceDictionary>
  </ResourceDictionary.ThemeDictionaries>
 </ResourceDictionary>
</Application.Resources>

这应该通过覆盖默认的UWP ResourceDictionary.ThemeDictionaries

来工作

答案 1 :(得分:0)

如上所述: How to change Highlight color of the selected ListView item in UWP (Windows 10)

更改当前资源

Application.Current.Resources["SystemControlHighlightListAccentLowBrush"] = new SolidColorBrush(Colors.Red);
Application.Current.Resources["SystemControlHighlightListAccentMediumBrush"] = new SolidColorBrush(Colors.Red);

或定义您自己的ListViewItemPresenter