FAKE ERROR REPORTING

Giorgio Sfiligoi 636 Reputation points
2025-10-24T20:00:33.59+00:00

In my MET MAUI app I have a popup where the user is supposed to enter a password. Following is a partial snippet:

<Entry x:Name="password" IsPassword="True" HorizontalOptions="Fill" />

<Button Text="OK" Margin="20,0"
        Command="{Binding AcceptCommand}"
        CommandParameter="{Binding Text, Source={x:Reference password}, Mode=OneWay, x:DataType='Entry'}"/>

When the button 'OK' is clicked, it reports the password in the CommandParameter.

Oddly the compiler higlights Binding Text and reports the error: 'Text' is not accessible.

However, the compilation completes successfully and the program runs - then it was not an error after all.

This happens both in NET 9.0 and NET 10. I am using VS 2026.

Can anybody explain this apparent inconsistency, and suggest a method to avoid this annoying fake error?

Developer technologies | .NET | .NET Multi-platform App UI

2 answers

Sort by: Oldest
  1. Starry Night 630 Reputation points
    2025-10-27T02:01:35.87+00:00

    Please try the following code, which works on my side:

    <?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:MauiApp1027"
                 x:Class="MauiApp1027.MainPage">
        <ContentPage.BindingContext>
            <local:TestViewModel></local:TestViewModel>
        </ContentPage.BindingContext>
       <VerticalStackLayout
                Padding="30,0"
                Spacing="25">
                <Entry x:Name="password" IsPassword="True"  HorizontalOptions="Fill" />
                <Button Text="OK" Margin="20,0"
            Command="{Binding AcceptCommand}"
            CommandParameter="{Binding x:DataType='Entry', Path= Text, Source={x:Reference password}, Mode=OneWay  }" />
       </VerticalStackLayout>
    </ContentPage>
    

    TestViewModel.cs

        public class TestViewModel
        {
            public ICommand AcceptCommand { get; set; }
            public TestViewModel() {
                AcceptCommand = new Command <string>(acceptCommand);
            }
            private void acceptCommand(string obj)
            {
                 App.Current.MainPage.DisplayAlert("Alert", "The passed data is: "+ obj, "OK");
            }
        }
    

    Was this answer helpful?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.