Answered by:
Change the default purple color of a selectedItem in a comboBox or listView

Question
-
I binged a bid but did not found any example on how to change the default purple color to for example blue.Monday, February 17, 2014 10:39 PM
Answers
-
Hi,
Do you try the other method i recommend you? You can define a SolidColorBrush in page resource and then use it in ListViewItemStyle.I do not why your generic.xaml cannot be edit. In my computer everything is ok. Do you create your app in windows 8.1? If so, StandardStyles.xaml is getted rid. And Generic.xaml contains the default styles and templates for most of the xaml controls, if you want to see the details of these styles you can use the great template-editing features in Visual Studio/Blend to inspect them as well.Once you have the style you can now also F12 (Go to definition) on the Style itself!!!! This will take you to the definition of the style in the framwork’s generic.xaml. If you create your app in windows 8, the StandardStyles.xaml contains the default styles and templates for most of the xaml controls,you can edit the ListViewItemSelectedBackgroundThemeBrush in it.
Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Friday, February 21, 2014 7:16 AM
All replies
-
Hi,
You can define a listview in xaml like below:
<ListView> <ListView x:Name="listView1" ItemContainerStyle="{StaticResource ListViewItemStyle1}" > <x:String>Item 1</x:String> <x:String>Item 2</x:String> <x:String>Item 1</x:String> <x:String>Item 2</x:String> </ListView> </ListView>
In the visual studio xaml designer you can go in the Outline windows, click right on the the ListView in the tree, click Edit Additional Template>Edit Item Container Style>Edit a copy. It will generate a copy of the ListViewItem Style and then you can replace ListViewItemSelectedBackgroundThemeBrush in this style by whatever color you want. You can select the ListViewItemSelectedBackgroundThemeBrush,then right click to select "go to definition" ,you can see ListViewItemSelectedBackgroundThemeBrush style in generic.xaml:
<SolidColorBrush x:Key="ListBoxItemSelectedBackgroundThemeBrush" Color="#FF4617B4" />
You can edit the color of ListBoxItemSelectedBackgroundThemeBrush, so you can change the selectedItem color in listview.
Another method,you can define a SolidColorBrush in page resource and then use it in ListViewItemStyle:
<SolidColorBrush x:Key="SelectedBackgroundThemeBrush" Color="Orange" />
In the below sample, I replace the ListViewItemSelectedBackgroundThemeBrush to SelectedBackgroundThemeBrush:
<Style x:Key="ListViewItemStyle1" TargetType="ListViewItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="True"/>
<Setter Property="Margin" Value="0,0,18,2"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}" ContentMargin="4" ContentTransitions="{TemplateBinding ContentTransitions}" CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}" DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" PointerOverBackgroundMargin="1" PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" SelectionCheckMarkVisualEnabled="True" SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" SelectedBackground="{StaticResource SelectedBackgroundThemeBrush }" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.
- Edited by Anne Jing Tuesday, February 18, 2014 2:49 AM edit
Tuesday, February 18, 2014 2:12 AM -
Hey thanks for the fast reply, i did what you gave me but the generic.xaml is a read only file for me, how do i change stuff in it?
- Edited by x ApolluMi x Thursday, February 20, 2014 6:41 PM
Thursday, February 20, 2014 3:18 PM -
Hi,
Do you try the other method i recommend you? You can define a SolidColorBrush in page resource and then use it in ListViewItemStyle.I do not why your generic.xaml cannot be edit. In my computer everything is ok. Do you create your app in windows 8.1? If so, StandardStyles.xaml is getted rid. And Generic.xaml contains the default styles and templates for most of the xaml controls, if you want to see the details of these styles you can use the great template-editing features in Visual Studio/Blend to inspect them as well.Once you have the style you can now also F12 (Go to definition) on the Style itself!!!! This will take you to the definition of the style in the framwork’s generic.xaml. If you create your app in windows 8, the StandardStyles.xaml contains the default styles and templates for most of the xaml controls,you can edit the ListViewItemSelectedBackgroundThemeBrush in it.
Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Friday, February 21, 2014 7:16 AM