dotnet / dotnet/wpf

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

Open
#11,111 0 comments 1 reaction 1 assignee Claimed by @dipeshmsft View on GitHub
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### 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; }
}
```
3. Add a TextBlock to the Window with the following style:
```


<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>

```
4. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.