Customize color of Selection Indicator from NavigationItemView

1 Answer 109 Views
NavigationView
Patrick
Top achievements
Rank 2
Patrick asked on 21 Jun 2024, 02:52 PM | edited on 21 Jun 2024, 03:13 PM

 

Hi team,

I am wondering how to customize the color of the selection indicator, the small vertical colored bar that appears when an item in the Navigation control is selected.

The current color seems to be the accent color of the device, for example, on Windows, the accent color from the theme Windows customization.

I tried to change the BackgroundColor on the NavigationViewItemView, but that doesn't work for the small indicator.

In your project sample, the small menu where you can select "First look," "Configuration," etc., is built with a telerik:NonVirtualizedItemsControl.

And this control have that style targetted telerik:NonVirtualizedItemsControlItemContainer

    <Style x:Key="SelectedManagerMenuItemStyle" TargetType="telerik:NonVirtualizedItemsControlItemContainer">
        <Setter Property="BackgroundColor" Value="{StaticResource AccentColor8}" />
    </Style>

And THAT change the indicator for the selected item like I need for the Navigation Controle.

My question is how to change the color of that indicator ?

 

Patrick
Top achievements
Rank 2
commented on 21 Jun 2024, 05:17 PM | edited

Hmmm, well, I saw other controls like RadComboBox that have that selection indicator. Is there a way to override the system accent color from the app?

I also tried to change that property like you did in the sample project, directly in the App() constructor:

Application.AccentColor = Color.FromArgb("#8660C5");

But it seems like this has no effect.

Lance | Senior Manager Technical Support
Telerik team
commented on 21 Jun 2024, 09:13 PM

Hi Patrick, I can confirm that it uses the AccentColor. Here is a screenshot of the ControlTemplate responsible for the visual element on WinUI

Unfortunately, even after overriding the entire template, I was not able to change the color either.

So, to get you some help with this,  I have escalated this thread to the UI for Maui team, who will be able to assist further. Someone form the team will reply with an answer.

1 Answer, 1 is accepted

Sort by
1
Accepted
Yana
Telerik team
answered on 24 Jun 2024, 11:21 AM

Hi Patrick,

Indeed, as Lance suggested, you'd need to override the NavigationViewItem template in order to modify that accent color.  The suggested solution does not work as the ItemStyle property is applied only for auto-generated items ( through the NavigationView's ItemsSource property).

In the concrete case, you can just use an implicit style like this:

<Style TargetType="telerik:NavigationViewItemView">
    <Setter Property="ControlTemplate" Value="{OnPlatform Default={StaticResource NavigationViewItemView_ControlTemplate}, 
                                                            WinUI={StaticResource NavigationViewItemView_ControlTemplate_WinUI}}" />
</Style>

Please find attached a sample app which demonstrates the exact approach.

I hope I was of help. Let me know if you have any additional questions on this.

Regards,
Yana
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Patrick
Top achievements
Rank 2
commented on 03 Jul 2024, 08:20 PM

It's perfect ! Overriding the ControlTemplate work perfectly !!!

Thanks !

Tags
NavigationView
Asked by
Patrick
Top achievements
Rank 2
Answers by
Yana
Telerik team
Share this question
or