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 8267775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:39:14+00:00 2026-06-08T05:39:14+00:00

Short version: WPF seems to always set a local value when using an IValueConverter

  • 0

Short version:
WPF seems to always set a local value when using an IValueConverter in a binding, even if that converter returns Binding.DoNothing.
My question is: What do I have to return or do to tell WPF to use the inherited value?

Please note: I don’t want to use DataTriggers as this would bloat up my code significantly because I would need one data trigger along with a converter for every color my current converter returns.


Long version with reproduction:

Imagine the following scenario:
I have a Button in which a TextBlock is located. There exists a style for the Button that sets the Foreground property. This value is inherited by the TextBlock.
Now I want to create a value converter that converts the value of the TextBlock to a Brush to be used as the Foreground – but only in some cases. In the cases in which I don’t want to set a special color, I return Binding.DoNothing. My understanding was that this would make the TextBlock to continue to use the inherited value.

Unfortunatelly, my understanding was not correct. Even when returning Binding.DoNothing a local value is set. This has been verified with Snoop.

The problem can be easily reproduced with this simple example:

XAML:

<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication1="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525">
  <Window.Resources>
    <WpfApplication1:DummyConverter x:Key="DummyConverter" />
    <Style TargetType="{x:Type Button}">
      <Setter Property="Foreground" Value="Red" />
    </Style>
    <Style TargetType="{x:Type TextBlock}">
          <Setter Property="Foreground"
                  Value="{Binding Path=Text, RelativeSource={RelativeSource Self}, Converter={StaticResource DummyConverter}}" />
    </Style>
  </Window.Resources>
  <StackPanel>
    <Button><TextBlock>Text1</TextBlock></Button>
    <Button><TextBlock>Text2</TextBlock></Button>
  </StackPanel>
</Window>

Converter:

public class DummyConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value.ToString() == "Text2")
            return Brushes.Cyan;
        return Binding.DoNothing;
    }
}

As you can see, the first button has a black text instead of red. If you remove the style for TextBlock both buttons will have the correct red text.

Question:
What do I have to do to prevent this? Is there some value to return that tells the engine to continue using the inherited value?

  • 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-08T05:39:16+00:00Added an answer on June 8, 2026 at 5:39 am

    To answer your question: according to this thread, no. As soon as you give the TextBlock a style setter (#4), any value returned will override inherited properties (#7).

    Instead, you could create a MultiBinding like so:

    public class DummyConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values[0].ToString() == "Text2")
                return Brushes.Cyan;
    
            return values[1];
        }
    }
    
    <Window x:Class="Spritefire.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Spritefire"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <local:DummyConverter x:Key="DummyConverter" />
            <Style TargetType="{x:Type Button}">
                <Setter Property="Foreground" Value="Red" />
            </Style>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="Foreground">
                    <Setter.Value>
                        <MultiBinding Converter="{StaticResource DummyConverter}">
                            <Binding Path="Text" RelativeSource="{RelativeSource Self}" />
                            <Binding Path="Foreground" ElementName="ExampleButton" />
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <StackPanel>
            <Button x:Name="ExampleButton">
                <TextBlock>Text1</TextBlock>
            </Button>
            <Button>
                <TextBlock>Text2</TextBlock>
            </Button>
        </StackPanel>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: $count in the code below seems to be 0 even when it
Short Version The MSDN documentation for Type.GetProperties states that the collection it returns is
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
Short Version: When I exit the App (home button), UIApplicationExitsOnSuspend is set to NO
Short Version I want an ADPlus script that will do a full memory dump
Short version: Is there a simple way to get the value of a primary
Short version: How can I get a regex that matches a@a.aaaa but not a@a.aaaaa
Short Version (tl;dr): Is there an open source or commercial engine that provides embeddable
I have a .NET 4 WPF app that gets installed using an MSI, generated
Short Version If I update the Model object that my ViewModel wraps, what's a

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.