Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Practicing Data Binding | Interactive GUI
C# Desktop Development with .NET MAUI

Challenge: Practicing Data Binding

Desliza para mostrar el menú

The base program is given on the Github Repository. Clone the repository to begin solving the task.

In the base code's XAML, there are two elements, one of them is a Checkbox, while the other is a Label.

Your task is to bind the Checkbox's IsChecked property with the Label's Text property such that, when the Checkbox is checked, it sets the Label to "Is checkbox checked? True" and if it's not then the Label is set to "Is checkbox checked? False".

You only have to modify the C# file.

Hint
expand arrow

Hint 1: In this case, the target is the label and the source is the checkbox.

Hint 2: We use the following syntax for binding properties:

targetElement.SetBinding(
    TargetElementType.TargetProperty,
    new Binding("path to property", source: sourceElement)
);
Solution
expand arrow
namespace MAUIDataBindingTask
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();

            mainLabel.SetBinding(Label.TextProperty, new Binding("IsChecked", source: mainCheckbox, stringFormat: "Is checkbox checked? {0}"));
        }
    }
} 
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 8

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 2. Capítulo 8
some-alt