Advertisement

XAML & Markup Extensions interview questions and answers

6 XAML & Markup Extensions interview questions for .NET MAUI roles, each with a model answer, examples and likely follow-ups.

6 questions
Advertisement

6 questions

Q1 Beginner Save

What are markup extensions in XAML?

Markup extensions provide values to XAML attributes at parse time using {} syntax, e.g., {Binding}, {StaticResource}, {DynamicResource}, {x:Static}, {OnPlatform}, {OnIdiom}. They let you reference resources, bind data, or compute values declaratively instead of hardcoding.
<Label Text="{Binding Title}"
       TextColor="{StaticResource Primary}"
       FontSize="{OnPlatform iOS=17, Android=16}" />
Real-world example
One label pulls its text from a binding, its color from a resource, and a platform-specific font size—all via markup extensions.
Likely follow-ups
  • Name a few built-in extensions. | What syntax do they use?
Markup XAML & UI Layouts XAML & Markup Extensions
Q2 Beginner Save

What do OnPlatform and OnIdiom do?

OnPlatform supplies different values per platform (iOS/Android/WinUI/MacCatalyst); OnIdiom supplies values per device type (Phone/Tablet/Desktop/TV/Watch). They're used inline in XAML to tweak sizes, margins, or resources without code-behind branching.
<StackLayout Padding="{OnPlatform iOS='20,40,20,20',
                                  Android='20'}"
             Spacing="{OnIdiom Phone=8, Desktop=16}" />
Real-world example
Extra top padding accommodates the iOS status bar while Android uses uniform padding, and spacing grows on desktop.
Likely follow-ups
  • OnPlatform vs OnIdiom? | Can they return complex values?
Markup Responsive UI XAML & Markup Extensions
Q3 Intermediate Save

What is x:Static and when do you use it?

x:Static references a static field, property, constant, or enum member from XAML, e.g., a color in a static class or an app constant. It's handy for sharing constants between C# and XAML without wrapping them in resources.
<Label TextColor="{x:Static local:AppColors.Brand}"
       Text="{x:Static local:AppStrings.Welcome}" />
Real-world example
Brand colors and shared strings defined as C# constants are referenced directly in XAML via x:Static.
Likely follow-ups
  • x:Static vs StaticResource? | Can it reference enums?
Markup Resources XAML & Markup Extensions
Q4 Intermediate Save

How do you create a custom markup extension?

Implement IMarkupExtension (or IMarkupExtension<T>) with a ProvideValue method returning the computed value, expose properties as inputs, and use it in XAML with {local:MyExtension ...}. Useful for translation lookups, computed values, or DI-resolved values.
public class TranslateExtension : IMarkupExtension<string>
{
    public string Key { get; set; }
    public string ProvideValue(IServiceProvider sp) =>
        AppResources.ResourceManager.GetString(Key) ?? Key;
    object IMarkupExtension.ProvideValue(IServiceProvider sp)
        => ProvideValue(sp);
}
Real-world example
A {local:Translate Key=Welcome} extension localizes text inline from resource files.
Likely follow-ups
  • What method must you implement? | Give a use case.
Markup Localization XAML & Markup Extensions
Q5 Advanced Save

What is the difference between StaticResource and DynamicResource?

StaticResource resolves the resource once at load time—efficient but won't reflect later changes. DynamicResource keeps a live link, updating the target if the resource is replaced (e.g., swapping a theme dictionary at runtime). Use DynamicResource only where runtime changes are needed, since it has slight overhead.
<!-- Updates live if 'Primary' is swapped at runtime -->
<Button BackgroundColor="{DynamicResource Primary}" />
Real-world example
Theme colors use DynamicResource so switching light/dark at runtime recolors the UI instantly, while static values use StaticResource.
Likely follow-ups
  • When must you use DynamicResource? | What's the performance trade-off?
Resources Themes XAML & Markup Extensions
Q6 Advanced Save

How do compiled XAML (XamlC) and x:DataType improve XAML?

XAML compilation (on by default) converts XAML to IL at build time, catching markup errors early and speeding load versus runtime parsing. Adding x:DataType enables compiled bindings, replacing reflection with generated accessors. Together they give build-time validation and better runtime performance.
[XamlCompilation(XamlCompilationOptions.Compile)]  // default in MAUI
// plus x:DataType on views for compiled bindings
Real-world example
A typo in a XAML element name becomes a build error instead of a runtime crash because XAML is compiled.
Likely follow-ups
  • What does x:DataType add? | Is XAML compilation on by default?
Performance & Optimization Data Binding & MVVM XAML & Markup Extensions