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

Icon binding with MVVM not working #117

Closed
Tracked by #109
ricavir11 opened this issue Aug 29, 2024 · 4 comments · Fixed by #109
Closed
Tracked by #109

Icon binding with MVVM not working #117

ricavir11 opened this issue Aug 29, 2024 · 4 comments · Fixed by #109
Assignees
Labels
Area-Core Enhancement New feature or request
Milestone

Comments

@ricavir11
Copy link

Icon is not displayed when a binding is applied with MVVM.

ViewModel example :

private FontAwesomeSolidIcons _myIcon;
public FontAwesomeSolidIcons MyIcon
{
            get => _myIcon;
            set
            {
                _myIcon = value;
                RaisePropertyChanged(() => MyIcon);
            }
}

public async Task PageAppearingAsync()
{
             MyIcon = FontAwesomeSolidIcons.AddressBook;
}

Related view component (Button)

<Button    
    Command="{Binding SearchAddressCommand}"
    Text="{mi:FontAwesomeSolid BindingContext={x:Reference HomeViewPage}, Icon={Binding MyIcon}, IconColor={DynamicResource 
   PrimaryColor}, IconSize=25}" />

@AathifMahir AathifMahir self-assigned this Aug 29, 2024
@AathifMahir
Copy link
Owner

Icon is not displayed when a binding is applied with MVVM.

ViewModel example :

private FontAwesomeSolidIcons _myIcon;
public FontAwesomeSolidIcons MyIcon
{
            get => _myIcon;
            set
            {
                _myIcon = value;
                RaisePropertyChanged(() => MyIcon);
            }
}

public async Task PageAppearingAsync()
{
             MyIcon = FontAwesomeSolidIcons.AddressBook;
}

Related view component (Button)

<Button    
    Command="{Binding SearchAddressCommand}"
    Text="{mi:FontAwesomeSolid BindingContext={x:Reference HomeViewPage}, Icon={Binding MyIcon}, IconColor={DynamicResource 
   PrimaryColor}, IconSize=25}" />

Would mind sharing a repro sample on this, in our testing binding just works fine.

@ricavir11
Copy link
Author

Yes I will try to provide it soon.
In my current project I'm using MVVM Helpers library but I will provide an example without it.
Nevertheless, it would be interesting to provide a simple sample with MVVM bindings

@vonmbs
Copy link

vonmbs commented Sep 2, 2024

Hey i had the same problem. I fixed it by adding the MVVM BindingContext to the XAML and reference it by name instead of adding it in the code behind.

Example:

<ContentPage ...>
  <ContentPage.BindingContext>
      <local:MainViewModel x:Name="MainViewModelName" />
  </ContentPage.BindingContext>
  ...
  <mi:MauiIcon Icon="{mi:FontAwesomeSolid Icon={Binding MyIcon},BindingContext={x:Reference MainViewModelName}}" />
  ...
</ContentPage>

@AathifMahir AathifMahir added Enhancement New feature or request Area-Core labels Sep 8, 2024
@AathifMahir AathifMahir added this to the v4.0.0 milestone Sep 8, 2024
@AathifMahir
Copy link
Owner

We have made a some improvements to overall binding support with v4 and that makes this no longer issue at all.

Additionally, we are final stage of the release. Stay tuned for v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Core Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants