Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BurkusCat opened this issue Oct 2, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@BurkusCat
Copy link
Owner

BurkusCat commented Oct 2, 2023

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

@BurkusCat BurkusCat added the enhancement New feature or request label Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant