dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.06k stars 1.73k forks source link

ToolbarItem icon doesn't work with MVVM Binding on iOS #20508

Closed AncientLust closed 1 month ago

AncientLust commented 8 months ago

Description

ToolbarItem icon doesn't work with MVVM Binding on iOS

This doesn't work:

<ContentPage.ToolbarItems>
    <ToolbarItem>
        <ToolbarItem.IconImageSource>
            <FileImageSource File="{Binding FilterStatusIcon}" />
        </ToolbarItem.IconImageSource>
    </ToolbarItem>
</ContentPage.ToolbarItems>

public partial class MainPageVM : ObservableObject
{
    [ObservableProperty] private string filterStatusIcon = "filter";
}

with binding

While this one does:

<ContentPage.ToolbarItems>
    <ToolbarItem>
        <ToolbarItem.IconImageSource>
            <FileImageSource File="filter" />
        </ToolbarItem.IconImageSource>
    </ToolbarItem>
</ContentPage.ToolbarItems>

without binding

Steps to Reproduce

  1. Open repro proj
  2. Deploy to iOS device
  3. Check that icon wasn't showed
  4. Replace binding by direct icon name: File="{Binding FilterStatusIcon}" -> File="filter"
  5. Redeploy, icon will appear

Link to public reproduction project repository

https://github.com/AncientLust/ToolBarItem-icon-binding-issue

Version with bug

8.0.6

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

ghost commented 8 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

PureWeen commented 8 months ago

@AncientLust if you bind to the text does the text binding work?

AncientLust commented 8 months ago

@PureWeen but text binding is exactly what I attached above (File name binded with string property FilterStatusIcon).

Or I don't get the quesiton, what do you mean?

JayMansel commented 8 months ago

It's not due to the property casing is it? filterStatusIcon in your VM and FilterStatusIcon in your XAML?

AncientLust commented 8 months ago

@JayMansel naah, MVVM generates property with capital letter:

public string FilterStatusIcon
{
    get => filterStatusIcon;
    [global::System.Diagnostics.CodeAnalysis.MemberNotNull("filterStatusIcon")]
    set
    {
        if (!global::System.Collections.Generic.EqualityComparer<string>.Default.Equals(filterStatusIcon, value))
        {
            OnFilterStatusIconChanging(value);
            OnFilterStatusIconChanging(default, value);
            OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.FilterStatusIcon);
            filterStatusIcon = value;
            OnFilterStatusIconChanged(value);
            OnFilterStatusIconChanged(default, value);
            OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.FilterStatusIcon);
        }
    }
}

It even doesn't work with lower one:

image