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

Binding does not work for Platform dependent Behaviors #11729

Closed
YMichurin opened this issue Nov 29, 2022 · 1 comment
Closed

Binding does not work for Platform dependent Behaviors #11729

YMichurin opened this issue Nov 29, 2022 · 1 comment
Labels
external t/bug Something isn't working

Comments

@YMichurin
Copy link

YMichurin commented Nov 29, 2022

Description

Binding to observable property does not work in platform behaviors. Try any platform behavior community mvvm toolkit provides:

https://github.com/CommunityToolkit/Maui/tree/main/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors

or create your own, you would get the same result.

Here is an original stackoverflow thread https://stackoverflow.com/questions/74607699/binding-does-not-work-for-platform-dependent-behaviors

Steps to Reproduce

Take for example StatusBarBehavior, write something like

    <ContentPage.Behaviors>
        <toolkit:StatusBarBehavior StatusBarColor="{Binding StatusBarColorProp}" StatusBarStyle="LightContent" />
    </ContentPage.Behaviors>

create the property in your view model

    [ObservableProperty]
    private Color _statusBarColorProp;

Update the property value in code-behind or model like StatusBarColorProp=Color.FromRgb(255,0,0). You'll see status bar color does not change with StatusBarBehavior property change in runtime. Same for all the rest of behaviors. It works fine for non-bindings setters like StatusBarColor="Red".

Link to public reproduction project repository

https://github.com/CommunityToolkit/Maui/tree/main/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

at least Android API 32 that I tested on, but does not seem to be platform dependent

Did you find any workaround?

interestingly while binding does not work for viewmodel, it does if you bind it to other control.

For example if you take BlurBehaviour from the repository https://github.com/VladislavAntonyuk/MauiSamples/tree/main/MauiImageEffects.

This code works fine:

<Image.Behaviors>
   <bh:BlurBehavior Radius="{Binding Value, Source={x:Reference imageBlurSlider}}"/>
</Image.Behaviors>

But this one does not

<Image.Behaviors>
   <bh:BlurBehavior Radius="{Binding MyMvvmBlurProperty}"/>
</Image.Behaviors>

Relevant log output

No response

@rachelkang
Copy link
Member

This issue was moved to CommunityToolkit/Maui#795

@dotnet dotnet locked and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants