Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoubleToObjectConverter doesn't work in some cases #4854

Open
2 of 14 tasks
Donsroom opened this issue Mar 13, 2023 · 1 comment
Open
2 of 14 tasks

DoubleToObjectConverter doesn't work in some cases #4854

Donsroom opened this issue Mar 13, 2023 · 1 comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Milestone

Comments

@Donsroom
Copy link

Donsroom commented Mar 13, 2023

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.

@Donsroom Donsroom added the bug 🐛 An unexpected issue that highlights incorrect behavior label Mar 13, 2023
@ghost ghost added the needs triage 🔍 label Mar 13, 2023
@ghost
Copy link

ghost commented Mar 13, 2023

Hello Donsroom, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
Status: No status
Development

No branches or pull requests

2 participants