dotnet / dotnet/wpf

Binding errors when using a Ribbon outside of a RibbonWindow

Open
#11,860 0 comments 0 reactions 0 assignees View on GitHub
Bug Cost:S PR Proposed Priority:3
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

When using the Ribbon control in a regular Window (or any Window that is not a RibbonWindow) using the default template, there are two Binding errors in the output.

```
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Ribbon.RibbonWindow', AncestorLevel='1''. BindingExpression:Path=WindowState; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Ribbon.RibbonWindow', AncestorLevel='1''. BindingExpression:Path=IsActive; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object')
```

These two errors appear harmless but can fill up the logs for the applications that keep track of Binding errors, like our applications do.

These errors do not appear when using the Ribbon in a RibbonWindow, but from my understanding using a Ribbon outside of a RibbonWindow still seems to be a valid scenario.

### Reproduction Steps

Just use a Ribbon in a regular Window like this:

```




```

### Expected behavior

As far as I can tell using a Ribbon outside of a RibbonWindow is a supported scenario, so I would expect to not have any error.

### Actual behavior

There are two binding errors in the output:
```
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Ribbon.RibbonWindow', AncestorLevel='1''. BindingExpression:Path=WindowState; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Ribbon.RibbonWindow', AncestorLevel='1''. BindingExpression:Path=IsActive; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object')
```

### Regression?

Not that I am aware of. I only tested on .NET 8 and 10 but from the looks of it, I don't think it is a regression.

### Known Workarounds

Either:
- Overwrite the ControlTemplate for the Ribbon with a fixed one (the errors come from the default template, see "Other information")
- Ignore the errors

### Impact

No noticeable impact for the end user, but it can fill up the logs for the applications that keep track of all the Binding errors.

### Configuration

.NET 10.0.111, on Windows 11 x64

But I don't think it really matters for this issue.

### Other information

The errors seem to come from the default template for the Ribbon, there are two conditions that try to bind on the parent RibbonWindow even when there is no parent RibbonWindow [there](https://github.com/dotnet/wpf/blob/1cfc37f708f91ff4556bd25af414546c446f3a16/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Themes/Generic.xaml#L2844) and [there](https://github.com/dotnet/wpf/blob/1cfc37f708f91ff4556bd25af414546c446f3a16/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Themes/Generic.xaml#L2903).

We already have a fix internally and we intend to open a PR shortly to propose our fix.

Contributor guide

Open the contributing guide

Research direction

Start in src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Themes/Generic.xaml at the two template conditions linked in the issue, then reproduce the Ribbon in a regular Window and in a RibbonWindow. Verify that the default template no longer emits the two RelativeSource binding errors outside a RibbonWindow while the RibbonWindow behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.