dotnet / dotnet/maui

[Windows] BoolToVisibilityConverter returns the incorrect type

Open
#6,868 9 comments 0 reactions 0 assignees View on GitHub
area-xaml partner platform/windows s/triaged t/bug
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

I am using the `BoolToVisibilityConverter` converter in UWP XAML: https://github.com/dotnet/maui/blob/main/src/Compatibility/Core/src/Windows/BoolToVisibilityConverter.cs.

It took me a few hours debugging and banging my head against the wall to figure out why it is not working. The converter implements the `Microsoft.UI.Xaml.Data.IValueConverter` interface and is supposed to convert a `bool` value to a `Microsoft.UI.Xaml.Visibility` value. The converter actually returns `Microsoft.Maui.Visibility` however. This makes it useless in UWP XAML, because it returns the wrong type and not applicable in MAUI XAML, as it implements an incompatible interface.

### Steps to Reproduce

Run the following code in a MAUI application:

```csharp
var converter = new Microsoft.Maui.Controls.Compatibility.Platform.UWP.BoolToVisibilityConverter();
var visibility = converter.Convert(true, typeof(bool), null, null);
var type = visibility.GetType();

System.Diagnostics.Debug.WriteLine($"Converted value type: {type}");
System.Diagnostics.Debug.Assert(visibility is Microsoft.UI.Xaml.Visibility);
```

Examine the type of the value returned from the converter.

### Version with bug

Release Candidate 2 (current)

### Last version that worked well

Unknown/Other

### Affected platforms

Windows

### Affected platform versions

I have not tested on various versions of the different platforms.

### Did you find any workaround?

The only workaround I have found is to implement my own converter which returns the correct type.

### Relevant log output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with src/Compatibility/Core/src/Windows/BoolToVisibilityConverter.cs and run the reproduction from the issue in a Windows MAUI application. Done means Convert returns a Microsoft.UI.Xaml.Visibility value for UWP XAML, with coverage confirming the returned type.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.