Skip to content

Disable temperature converter button when input is empty#2090

Merged
marcelwgn merged 5 commits intomainfrom
copilot/fix-convert-to-fahrenheit-button
Dec 20, 2025
Merged

Disable temperature converter button when input is empty#2090
marcelwgn merged 5 commits intomainfrom
copilot/fix-convert-to-fahrenheit-button

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

The "Convert to Fahrenheit" button in the Temperature Converter UserControl was always enabled, allowing users to click it with no input.

Changes

TemperatureConverterControl.xaml

  • Bind button's IsEnabled property to HasText(InputTextBox.Text) using x:Bind function binding

TemperatureConverterControl.xaml.cs

  • Add HasText(string text) helper method
  • Check for !string.IsNullOrWhiteSpace(text)
private bool HasText(string text)
{
    return !string.IsNullOrWhiteSpace(text);
}

This implementation uses x:Bind function binding which automatically reevaluates when InputTextBox.Text changes, providing a lightweight solution without the need for INotifyPropertyChanged, event handlers, or backing fields.

Button state now updates in real-time as user types.

Original prompt

This section details on the original issue you should resolve

<issue_title>'Convert to Fahrenheit' button is in enable state when no text is entered in the edit field.</issue_title>
<issue_description>### Which version of the app?

WinUI 3 Gallery

Description

Environment Details:
OS Version: Dev (OS Build 27881.1000)
App: WinUI 3 Gallery
App Version: 2.6.0.0 (SDK 1.7)

Repro Steps:
Launch the WinUI 3 Gallery app.
Navigate to search box using tab key.
Type 'Custom &user controls' in search box and hit enter.
Navigate to 'Custom &user controls' card and activate it.
Navigate to "User Control" heading.
Observe ''Convert to Fahrenheit' button.
Actual Result:
'Convert to Fahrenheit' button is in enable state when no text is entered in the edit field.

Expected Result:
'Convert to Fahrenheit' button should be in disabled state when no text is entered in the edit field.

Page source link: https://github.com/microsoft/WinUI-Gallery/blob/main/WinUIGallery/Samples/ControlPages/Fundamentals/CustomUserControlsPage.xaml

Screenshots

No response

Windows version

Windows 11 24H2 (26100)

Additional context

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 18, 2025 10:26
Co-authored-by: ayushjai19 <244442986+ayushjai19@users.noreply.github.com>
…tion

Co-authored-by: ayushjai19 <244442986+ayushjai19@users.noreply.github.com>
…eException

Co-authored-by: ayushjai19 <244442986+ayushjai19@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix enabled state of convert to Fahrenheit button Disable temperature converter button when input is empty Dec 18, 2025
Copilot AI requested a review from ayushjai19 December 18, 2025 10:32
@ayushjai19 ayushjai19 marked this pull request as ready for review December 18, 2025 11:59
@marcelwgn
Copy link
Contributor

/azp run

Copy link
Contributor

@Zakariathr22 Zakariathr22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify the IsEnabled logic and avoid INotifyPropertyChanged entirely by using an x:Bind function binding. Since the button state is directly derived from the TextBox.Text, a small method is sufficient and keeps the control lightweight.

IsEnabled="{x:Bind HasText(InputTextBox.Text), Mode=OneWay}"
private bool HasText(string text)
{
    return !string.IsNullOrWhiteSpace(text);
}

@ayushjai19
Copy link
Collaborator

You can simplify the IsEnabled logic and avoid INotifyPropertyChanged entirely by using an x:Bind function binding. Since the button state is directly derived from the TextBox.Text, a small method is sufficient and keeps the control lightweight.

IsEnabled="{x:Bind HasText(InputTextBox.Text), Mode=OneWay}"
private bool HasText(string text)
{
    return !string.IsNullOrWhiteSpace(text);
}

@copilot consider above comment

Co-authored-by: ayushjai19 <244442986+ayushjai19@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 19, 2025

You can simplify the IsEnabled logic and avoid INotifyPropertyChanged entirely by using an x:Bind function binding. Since the button state is directly derived from the TextBox.Text, a small ...

Implemented the simplified approach using x:Bind function binding in commit f10e4e3. The solution is now much cleaner with just a HasText helper method, eliminating the need for INotifyPropertyChanged, event handlers, and backing fields.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1p7vsblobprodcus324.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/E25CD4A82AF7DCCAC78C9E3EDD9CC1BB/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/7F0AD5B89EC078FE77CFD6BDA2F52E08/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • 51yvsblobprodcus36.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/9385D6F79C8C3B1189EF0A92FFB71E10/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/EB23B7D1B15B85081672081E55C17E18/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • 6s7vsblobprodcus313.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/7F0AD5B89EC078FE77CFD6BDA2F52E08/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • 96bvsblobprodcus338.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/tests/WinUIGallery.UITests/WinUIGallery.UITests.csproj --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
  • crl.godaddy.com
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/C1A6874189F3A3E4F1A43CCA7F065BAD/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • e7bvsblobprodcus348.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/WinUIGallery.sln --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/WinUIGallery.DesktopWap.sln --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/WinUIGallery/WinUIGallery.csproj --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
  • ibzvsblobprodcus369.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/tests/WinUIGallery.UITests/WinUIGallery.UITests.csproj --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
  • k4kvsblobprodcus344.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/AFED770A6C82C3D0C8515A8A32ECB221/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • kmuvsblobprodcus389.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/0A8D2B0114395BB81780675AAD5BD541/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • o3svsblobprodcus318.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/DC729DA7A00C49E806D9BECF97EED2B3/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force sharp/working/emptyFakeDotnetRoot csharp/working/emptyFakeDotnetRoot (dns block)
  • ocsp.godaddy.com
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/C1A6874189F3A3E4F1A43CCA7F065BAD/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • pkvvsblobprodcus321.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/tests/WinUIGallery.UITests/WinUIGallery.UITests.csproj --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/7F0AD5B89EC078FE77CFD6BDA2F52E08/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • vwvvsblobprodcus334.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/780211A2D4C6297318C9E18BBEC72052/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • yluvsblobprodcus367.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/AFED770A6C82C3D0C8515A8A32ECB221/missingpackages_workingdir --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/missingpackages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal --configfile /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/nugetconfig/nuget.config --force (dns block)
  • ytvvsblobprodcus310.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/WinUI-Gallery/WinUI-Gallery/tests/WinUIGallery.UITests/WinUIGallery.UITests.csproj --packages /home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/WinUI-Gallery/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@marcelwgn marcelwgn enabled auto-merge (squash) December 20, 2025 12:40
@marcelwgn
Copy link
Contributor

/azp run

@marcelwgn marcelwgn merged commit 5218037 into main Dec 20, 2025
4 checks passed
@marcelwgn marcelwgn deleted the copilot/fix-convert-to-fahrenheit-button branch December 20, 2025 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'Convert to Fahrenheit' button is in enable state when no text is entered in the edit field.

4 participants