How can I change the border color of a NavigationView in WinUI 3?

youki 1,021 Reputation points
2024-05-22T15:53:25.08+00:00

Which property is it in the generic.xaml? I can't even find the TargetType.

Lines within the red rectangles.

User's image

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
794 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
{count} vote

Accepted answer
  1. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2024-05-23T02:23:44.8833333+00:00

    Hello @youki,

    There are no such properties for this. But you can use the VisualTreeHelper Class to find the desired element and change its properties when the NavigationView is loaded. NavigationView is defined like:

    <Style TargetType="controls:NavigationView">
        ...
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:NavigationView">
                    ...
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tech5G5G 0 Reputation points
    2024-08-10T20:10:21.9533333+00:00

    Hi @youki

    As you have mentioned, there is no property for this, but there is a key you can add to the NavigationView's resources named "NavigationViewContentGridBorderBrush".

    Here's what you need to add to your NavigationView:

    <NavigationView.Resources>
        <SolidColorBrush x:Key="NavigationViewContentGridBorderBrush" Color="" />
    </NavigationView.Resources>
    

    You can set the value of Color to your desired color. Here are some examples:

    Unchanged (for reference) Red Transparent (removes border)
    User's image User's image User's image

    Let me know if this answered your question!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.