Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I disable image in xaml?

How can I disable image if I can do it?

For example, [Build your first app link](https://i.stack.imgur.com/yUV9l.png)

MainPage.xaml

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?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"
             x:Class="AppMaui.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Padding="30,0"
            Spacing="25">
            <Image
                Source="dotnet_bot.png"
                HeightRequest="185"
                Aspect="AspectFit"
                SemanticProperties.Description="dot net bot in a race car number eight" />

            <Label
                Text="Hello, World!"
                Style="{StaticResource Headline}"
                SemanticProperties.HeadingLevel="Level1" />

            <Label
                Text="Welcome to &#10;.NET Multi-platform App UI"
                Style="{StaticResource SubHeadline}"
                SemanticProperties.HeadingLevel="Level2"
                SemanticProperties.Description="Welcome to dot net Multi platform App U I" />

            <Button
                x:Name="CounterBtn"
                Text="Click me" 
                SemanticProperties.Hint="Counts the number of times you click"
                Clicked="OnCounterClicked"
                IsEnabled="False"
                HorizontalOptions="Fill" />
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>

MainPage.xaml.cs

namespace AppMaui
{
    public partial class MainPage : ContentPage
    {
        int count = 0;

        public MainPage()
        {
            InitializeComponent();
        }

        private void OnCounterClicked(object sender, EventArgs e)
        {
            count++;

            if (count == 1)
                CounterBtn.Text = $"Clicked {count} time";
            else
                CounterBtn.Text = $"Clicked {count} times";

            SemanticScreenReader.Announce(CounterBtn.Text);
        }
    }

}

I want to disable image for default and make it enabled after clicking button.
I change image, add button

<Button
    x:Name="MakePictureButton"
    Text="Make counter" 
    SemanticProperties.Hint="button make picture of counter"
    Clicked="OnMakePictureClicked"
    HorizontalOptions="Fill" />

and write OnMakePictureClicked

private void OnMakePictureClicked(object sender, EventArgs e)
{
    if (count == 0)
    {
        CounterImage.IsEnabled = true;
        CounterBtn.IsEnabled = true;
        MakePictureButton.IsEnabled = false;
    }
}

but I still can see image before and after clicking any button.
I’m beginer in maui/c#/xaml.
What I need to do?
Can I do this by other way?

>Solution :

If you want to make the image disappear you can do this.

CounterImage.IsVisible = false;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading