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.21k stars 1.75k forks source link

Binding to object is null #16425

Open davidortinau opened 1 year ago

davidortinau commented 1 year ago

Description

When doing a binding to the item object the value is null in a value converter.

Example:

Text={Binding ., Converter={StaticResource MyConverter}}

This works in Xamarin.Forms but not MAUI. In MAUI I must supply a property.

Steps to Reproduce

See description

Link to public reproduction project repository

MAUI-samples

Version with bug

8.0.0-preview.5.8529

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)

Affected platform versions

All

Did you find any workaround?

Workaround is to add a getter on the object that returns itself.

public class MyObject {
  public MyObject Self {
    get { return this; }
  }
}

And then

Text={Binding Self, Converter={StaticResource MyConverter}}

Relevant log output

No response

Madde88 commented 1 year ago

Maybe related Button inside a collectionview worked in .net 7. Updated to .net 8 preview 6. Now the command parameter is null. Hardcode a value does work but not bind to it so the workaround does not work here.

<Button Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Text="TitleText" HorizontalOptions="End" VerticalOptions="CenterAndExpand" Command="{Binding BindingContext.GoToFollowTrackCommand, Source={x:Reference TracksCollection}}" CommandParameter="{Binding . }"/>

ghost commented 1 year 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.

StephaneDelcroix commented 1 year ago

we have test showing that this works, at least in some cases. do you have a sample case where it does not ?

StephaneDelcroix commented 8 months ago

can I close this, @davidortinau ?