BurkusCat / Burkus.Mvvm.Maui

A simple MVVM framework for .NET MAUI. It provides: navigation, lifecycle events, parameter passing, native dialog abstractions, and testability.
MIT License
25 stars 5 forks source link

[Feature] Nested viewmodels or viewmodels for resuable controls #5

Open BurkusCat opened 11 months ago

BurkusCat commented 11 months ago

Is your feature request related to a problem? Please describe. Example: if you wanted to have a custom control called "NewsTickerView" with a viewmodel "NewsTickerViewModel". You may want this view to load its own news data so it can be individually unit tested. This view could then be embedded into multiple pages throughout your app without your other viewmodels needing to be coupled to your news ticker.

Describe the solution you'd like Use the markup extension to register a binding context for controls on a page? How would navigation events get called for these nested controls?

Describe alternatives you've considered N/A

Proposed APIs

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="DemoApp.Views.ChangeUsernamePage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:burkus="http://burkus.co.uk"
    xmlns:vm="clr-namespace:DemoApp.ViewModels"
    xmlns:views="clr-namespace:DemoApp.Views"
    x:DataType="vm:ChangeUsernameViewModel"
    BindingContext="{burkus:ResolveBindingContext x:TypeArguments=vm:ChangeUsernameViewModel}">
    <ScrollView>
        <!-- Nested control with a viewmodel that gets resolved -->
        <views:NestedView BindingContext="{burkus:ResolveBindingContext x:TypeArguments=vm:NestedViewModel}" />
    </ScrollView>
</ContentPage>

Additional context N/A