Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7714209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:04:19+00:00 2026-06-01T02:04:19+00:00

So I have this WPF style: <Style x:Key=SmallLinkButton TargetType=Button> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=Button>

  • 0

So I have this WPF style:

<Style x:Key="SmallLinkButton" TargetType="Button">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="Button">
            <TextBlock TextDecorations="Underline">
                <ContentPresenter />
            </TextBlock>
        </ControlTemplate>
    </Setter.Value>
</Setter>
    <Setter Property="Foreground" Value="#234D20" />
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Foreground" Value="#77AB59" />
        </Trigger>
    </Style.Triggers>
</Style>

To make a link button wich turns its color when the mouse is over. And I have a set of buttons with this style, I want to be able to, once the user has clicked the mouse, change the button foreground to the second value, unless he clicks another button.

It is posible to do this just by using the style? I don’t believe it, but I’m novice with WPF or, how would you implement this feature.

Thanks in advance.

Solution

As suggested by @Phil, the solution was to use a container, a listbox in this case, styled as:

<!-- Start of the menu -->
    <!-- Horizontal listbox-->
    <Style x:Key="MenuListBox" TargetType="ListBox">
        <Setter Property="BorderBrush" Value="{x:Null}" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- Listbox item with the special behavior -->
    <Style x:Key="MenuListBoxItem" TargetType="ListBoxItem">
        <Style.Resources>
            <!-- SelectedItem with focus -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                Color="Transparent" />
            <!-- SelectedItem without focus -->
            <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" 
                Color="Transparent" />
            <!-- SelectedItem text foreground -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" 
                Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}" />
        </Style.Resources>
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    </Style>
    <!-- Menu buttons -->
    <Style x:Key="BigMenuLinkButton" TargetType="TextBlock">
        <Setter Property="FontFamily" Value="Segoe UI Light"/>
        <Setter Property="FontSize" Value="36" />
        <Setter Property="Foreground" Value="#C9DF8A" />

        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Foreground" Value="#77AB59" />
            </Trigger>
            <DataTrigger Value="True" Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}">
                <Setter Property="Foreground" Value="#234D20"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
    <Style x:Key="MediumMenuLinkButton" TargetType="TextBlock">
        <Setter Property="FontSize" Value="24" />
        <Setter Property="Foreground" Value="#C9DF8A" />

        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Foreground" Value="#77AB59" />
            </Trigger>
            <DataTrigger Value="True" Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}">
                <Setter Property="Foreground" Value="#234D20"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
    <!-- End of the menu -->
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:04:20+00:00Added an answer on June 1, 2026 at 2:04 am

    Here’s an idea to get you started

    Style a list box so that the list box items look like your link buttons:

    Xaml

    <Page.Resources>
        <Style x:Key="SmallLinkButton" TargetType="TextBlock">
            <Setter Property="TextDecorations" Value="Underline"/>
            <Setter Property="Foreground" Value="#234D20" />
    
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter Property="Foreground" Value="#77AB59" />
                </Trigger>
                <DataTrigger Value="True" 
                     Binding="{Binding Path=IsSelected, 
                       RelativeSource={RelativeSource Mode=FindAncestor, 
                       AncestorType={x:Type ListBoxItem}}}">
                   <Setter Property="Foreground" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    
        <Style x:Key="NullSelectionListBoxItem" TargetType="ListBoxItem">
            <Style.Resources>
                <!-- SelectedItem with focus -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                    Color="Transparent" />
                <!-- SelectedItem without focus -->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" 
                    Color="Transparent" />
                <!-- SelectedItem text foreground -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" 
                    Color="{DynamicResource {x:Static SystemColors.ControlTextColorKey}}" />
            </Style.Resources>
            <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        </Style>
    </Page.Resources>
    
    <Page.DataContext>
        <Samples:LinkButtonsInListBoxViewModel/>
    </Page.DataContext>
    
    <Grid>
        <ListBox ItemsSource="{Binding Items}" 
                 ItemContainerStyle="{StaticResource NullSelectionListBoxItem}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Margin="5" 
                        Style="{StaticResource SmallLinkButton}" Text="{Binding}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
    

    C#

    public class LinkButtonsInListBoxViewModel
    {
        public LinkButtonsInListBoxViewModel()
        {
            Items = new List<string> {"One", "Two", "Three"};
        }
    
        public List<string> Items { get; private set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF button style below: <Style x:Key=myButtonStyle TargetType={x:Type Button}> <Setter Property=Template> <Setter.Value>
I have a WPF style that sets TextDecorations dependency property for TargetType: TexBlock .
I have a custom button,ColorPickerButton, in WPF and style ColorPickerButtonStyle is applied for it,
First of all, I am new to WPF. I have this style ready for
In our WPF app we have a global style with TargetType={x:Type ContextMenu} . I
In a WPF app I have a ResourceDictionary with Style defined for the TargetType
So, I have this desktop app built using WPF and C#. It's basically an
The CollectionViewSource.GetDefaultView() method is not in Silverlight 3. In WPF I have this extension
In my WPF application I have some drawing functionality. I have solved this using
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.