Search code examples
xamldata-bindingmauidesign-timedesign-time-data

Designing in MAUI - Design-time BindingContext


In WPF, I used the normal combination of:

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignData...}"

To allow a design-time DataContext to be set. This meant that I got reasonable Intellisense in my XAML. I realise the above code doesn't compile but you get the idea.

I've just started using MAUI (without Blazor) and am looking to achieve the same thing - so that I can tell Visual Studio that my ContentView will be bound to a specific object type, ie d:BindingContext="" in a way that will be ignored at runtime? It would make designing ItemTemplates so much easier!


Solution

  • Thanks for Jason's comment. I actually came across the answer to this question in a James Montemango video too.

    x:DataType is fantastic - it is stronger than the old system in that it actually provides compile-time protection for the bindings.

    Edit: The video in question is: https://youtu.be/3-cT97sBmxM