Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How do you set selected and unselcted foreground color for a textblock in a MenuItemTemplate for the NavigationView control? #3193

Closed
Going-Gone opened this issue Aug 25, 2020 · 5 comments
Labels
area-NavigationView NavView control question team-Controls Issue for the Controls team

Comments

@Going-Gone
Copy link

Going-Gone commented Aug 25, 2020

Is there a way to modify the template textblock behavior based on the navigation view visual state?
When the menu item is selected, the text foreground should be black.
When the menu item is not selected, the text foreground should be white.

I've not been able to figure out how to modify the behavior of the template textbox for the menu items.

      <DataTemplate x:Key="MenuItemTitleTemplate">
            <Grid >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Text="{Binding MenuItemText}" 
                           Style="{StaticResource NavigationViewItemHeaderTextStyle}" />
            </Grid>
        </DataTemplate>

   <muxc:NavigationView  
            x:Name="nvSubMenu" 
            IsBackButtonVisible="Collapsed"
            IsSettingsVisible="False"
            IsEnabled="True"
            HorizontalAlignment="Left"              
            PaneDisplayMode="Top"
            IsPaneToggleButtonVisible="False"
            AlwaysShowHeader="False"
            IsBackEnabled="False" 
            MenuItemsSource="{Binding list}"
            MenuItemTemplate="{StaticResource MenuItemTitleTemplate}">
        
    </muxc:NavigationView>

@Going-Gone to double-check, do you mean TextBox or TextBlock? You're using TextBlock in your data template.

Are you also planning on changing the background of the selected menu item to ensure the text remains legible?

@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label Aug 25, 2020
@YuliKl YuliKl changed the title Question: How do you set selected and unselcted foreground color for a textbox in a MenuItemTemplate for the NavigationView control? Question: How do you set selected and unselcted foreground color for a textblock in a MenuItemTemplate for the NavigationView control? Aug 25, 2020
@YuliKl YuliKl added area-NavigationView NavView control team-Controls Issue for the Controls team labels Aug 25, 2020
@YuliKl
Copy link

YuliKl commented Aug 25, 2020

@Going-Gone to double-check, do you mean TextBox or TextBlock? You're using TextBlock in your data template.

Are you also planning on changing the background of the selected menu item to ensure the text remains legible?

@YuliKl
Copy link

YuliKl commented Aug 25, 2020

If I'm understanding your scenario correctly, the easiest way to achieve this is with light weight styling. Overwrite the brushes defined for NavigationViewItemForeground* resources to use values you prefer.

<StaticResource x:Key="NavigationViewItemForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />

@YuliKl YuliKl added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners labels Aug 25, 2020
@Going-Gone
Copy link
Author

@Going-Gone to double-check, do you mean TextBox or TextBlock? You're using TextBlock in your data template.

Are you also planning on changing the background of the selected menu item to ensure the text remains legible?

Apologies, TextBlock.
Yep the background is set with

        <SolidColorBrush x:Key="TopNavigationViewItemBackgroundSelected" Color="White"/>
        <SolidColorBrush x:Key="NavigationViewItemBackground" Color="#477DAC"/>

@msft-github-bot msft-github-bot added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. labels Aug 26, 2020
@Going-Gone
Copy link
Author

If I'm understanding your scenario correctly, the easiest way to achieve this is with light weight styling. Overwrite the brushes defined for NavigationViewItemForeground* resources to use values you prefer.

<StaticResource x:Key="NavigationViewItemForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />

If I'm understanding your scenario correctly, the easiest way to achieve this is with light weight styling. Overwrite the brushes defined for NavigationViewItemForeground* resources to use values you prefer.

<StaticResource x:Key="NavigationViewItemForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />

That works, Thanks.

@YuliKl
Copy link

YuliKl commented Aug 26, 2020

Sounds like the question is resolved. Closing.

@YuliKl YuliKl closed this as completed Aug 26, 2020
@msft-github-bot msft-github-bot removed the needs-triage Issue needs to be triaged by the area owners label Aug 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NavigationView NavView control question team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

3 participants