I am upgrading my app to .NET 9 and previously used this to use commands from my page's vm in a datatemplate for listviews and such:
<ContentPage
...
x:Name="this"
x:DataType="viewmodel:MyViewModel">
...
<DataTemplate x:DataType="model:MyClass">
<Button
Command="{Binding Source={x:Reference this}, Path=BindingContext.MyCommand}}"
CommandParameter="{Binding .}" />
...
But now it seems due to the changes to compiled bindings, this no longer works. Does anyone know the new way of doing this? I've looked around online but all the answers are outdated and not specific to .NET 9.
I am upgrading my app to .NET 9 and previously used this to use commands from my page's vm in a datatemplate for listviews and such:
<ContentPage
...
x:Name="this"
x:DataType="viewmodel:MyViewModel">
...
<DataTemplate x:DataType="model:MyClass">
<Button
Command="{Binding Source={x:Reference this}, Path=BindingContext.MyCommand}}"
CommandParameter="{Binding .}" />
...
But now it seems due to the changes to compiled bindings, this no longer works. Does anyone know the new way of doing this? I've looked around online but all the answers are outdated and not specific to .NET 9.
Share Improve this question edited Mar 30 at 1:59 Ken White 126k15 gold badges236 silver badges466 bronze badges asked Mar 30 at 1:33 codybchaplincodybchaplin 1991 silver badge10 bronze badges1 Answer
Reset to default 3Well I ended up figuring it out soon after posting this thanks to this thread. I ended up changing:
Command="{Binding Source={x:Reference this}, Path=BindingContext.MyCommand}}"
to
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:MyViewModel}}, Path=MyCommand, x:DataType=viewmodel:MyViewModel}"