← All lessons

Level 1 / XAML + MVVM / lesson 1 of 6

Your first binding

Write a view model and bind one of its properties into XAML.

MVVM splits the screen in two. The view model is plain C# that knows nothing about the UI. The XAML view knows nothing about where the data comes from - it just asks for a property by name through `{Binding}`.

Understand the idea

View and view model

The XAML view declares controls; the view model exposes values and behavior. A binding connects a control property to a named property on the current data context.

The missing real-world step

The simulator supplies MainViewModel as the binding context automatically. A real WPF view must set DataContext, and a .NET MAUI view needs BindingContext, before {Binding Headline} can resolve.

Paths are contracts

The binding path must match a public property. Once connected, the view can display a new Headline value without hard-coding that text in XAML.

6 lines
4 lines

Preview - simulated. Not a .NET compiler.

Step 1 of 3

In progress

Write the view model

Add a public string property named Headline to MainViewModel, starting out as "Goose Solutions".

  • A class named MainViewModel exists - done
  • MainViewModel declares a public string property named Headline - not done yet
  • Headline starts out as "Goose Solutions" - not done yet

Coach

The checklist above is what decides whether a step is done. The coach only explains; it never grades.

The preview is a simulated XAML surface, not WPF, WinUI, or .NET MAUI. It renders StackPanel, Grid, TextBlock, Label, TextBox, Entry, and Button, and simulates INotifyPropertyChanged and ICommand. Layout attributes such as Margin and Width are accepted but not laid out. Anything else is reported as outside the lesson.

Where the simulator stops

The preview mixes a small subset of WPF and MAUI control names. Choose one real framework before copying the markup; its control names and binding-context setup may differ.

Try it in a real .NET project

Create a WPF project with MainViewModel and a Headline property. Set the window's DataContext to an instance of it, bind a TextBlock.Text to Headline, and confirm it appears when you run the app.

Check your understanding

Why can {Binding Headline} be correctly spelled yet show no text in a real WPF window?

Show the explanation

The window or control may not have the expected DataContext. Set it to a MainViewModel instance, then check that Headline is a public property on that object.

Goose School teaches Microsoft's stack. Goose Solutions is not affiliated with, endorsed by, or sponsored by Microsoft.