Skip to content

DataTrigger does not work if a markup extension contains a property named 'Value' #11111

@nicoweh

Description

@nicoweh

Description

The WPF DataTrigger does not trigger if a custom markup extension is used that contains a property named "Value" but the trigger works if any other property name is used.

Reproduction Steps

The bug can be reproduced with the following minimal example:

  1. Create a new WPF project.
  2. Create a class that inherits from Binding and contains a property "Value":
public class TestBindingExtension : Binding
{
    public TestBindingExtension() : base() { }

    public TestBindingExtension(string path) : base(path) { }

    public object? Value { get; set; }
}
  1. Add a TextBlock to the Window with the following style:
<TextBlock.Style>
    <Style TargetType="{x:Type TextBlock}">
        <Setter Property="Text" Value="NOT EXPECTED"/>
        <Style.Triggers>
            <DataTrigger Binding="{local:TestBinding Path=IsExpected, Value=anyvalue}" Value="True">
                <Setter Property="Text" Value="EXPECTED"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</TextBlock.Style>
  1. Ensure a DataContext is used so that the Binding returns true:
public MainWindow()
{
    InitializeComponent();
    DataContext = new { IsExpected = true };
}

Expected behavior

DataTrigger works correctly and the displayed text is "EXPECTED".

Actual behavior

DataTrigger does not work correctly and the displayed text is "NOT EXPECTED".

Regression?

No response

Known Workarounds

DataTrigger works as expected if at least one of the following conditions is changed:

  • Property has a name other than "Value"
  • an explicit data type is used for the Value property of the markup extension
  • an explicit data type is used for the Value property of the DataTrigger

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions