Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

DoubleToObjectConverter doesn't work in some cases #4854

@Donsroom

Description

@Donsroom

Describe the bug

If you create a resource for the DoubleToObjectConverter as follows (note that GreaterThan and LessThan are both set):

<wctconverters:DoubleToObjectConverter x:Key="ZeroDoubleToVisibilityConverter"
                                       GreaterThan="-1"
                                       LessThan="1"
                                       TrueValue="<somevalue>"
                                       FalseValue="<somevalue>"
                                       NullValue="<somevalue>" />

If the value is either greater than GreaterThan or less than LessThan the first if statement returns false as expected. However this results in one or the other of the following else if statements returning true which doesn't indicate that the value was not between the GreaterThan and LessThan values.

Regression

No response

Reproducible in sample app?

  • This bug can be reproduced in the sample app.

Steps to reproduce

1. Create an application.
2. Create a resource for a `DoubleToObjectConverter`.
3. In the resource specify values for BOTH `GreaterThan` AND `LessThan`.
4. Use the converter in a property in a xaml file.

Expected behavior

If the value passed to the converter is greater than GreaterThan or less than LessThan the converter should return FalseValue.

Screenshots

No response

Windows Build Number

  • Windows 10 1809 (Build 17763)
  • Windows 10 1903 (Build 18362)
  • Windows 10 1909 (Build 18363)
  • Windows 10 2004 (Build 19041)
  • Windows 10 20H2 (Build 19042)
  • Windows 10 21H1 (Build 19043)
  • Windows 11 21H2 (Build 22000)
  • Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • Windows 10, version 1809 (Build 17763)
  • Windows 10, version 1903 (Build 18362)
  • Windows 10, version 1909 (Build 18363)
  • Windows 10, version 2004 (Build 19041)
  • Other (specify)

Other SDK version

No response

Visual Studio Version

2022

Visual Studio Build Number

4.8.09032

Device form factor

Desktop

Nuget packages

CommunityToolkit.WinUI.UI 7.1.2
Microsoft.WindowsAppSDK 1.2.230217.4
Microsoft.Windows.SDK.BuildTools 10.0.22621.755

Additional context

Changing the following code in DoubleToObjectConverter.cs:

if (!double.IsNaN(GreaterThan) && !double.IsNaN(LessThan) && vd > GreaterThan && vd < LessThan)
{
    boolValue = true;
}
else if (!double.IsNaN(GreaterThan) && vd > GreaterThan)
{  
    boolValue = true;
}  
    else if (!double.IsNaN(LessThan) && vd < LessThan)
{ 
    boolValue = true;
}

To:

if (!double.IsNaN(GreaterThan) && !double.IsNaN(LessThan))
{
    if (vd > GreaterThan && vd < LessThan)
    {
         boolValue = true;
    }
}
else if (!double.IsNaN(GreaterThan) && vd > GreaterThan)
{  
    boolValue = true;
}  
    else if (!double.IsNaN(LessThan) && vd < LessThan)
{ 
    boolValue = true;
}
}

fixes the issue by isolating the logic for both values being set from the logic for only one value being set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛An unexpected issue that highlights incorrect behavior

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions