I can reproduce this issue and that's because Behaviours
don't have unique visual tree parents so Relativesource bindings do not work on it. Instead of using Relative Bindings, you may use x:Reference markup for binding.
For example, suppose the ContentView is placed in the DataTemplate
of a CollectionView
in a ContentPage
which set its BindingContext to ChatWIndowViewModel
. And we may first set the x:Name
for the ContentPage
(in this case we set x:Name
to page
), and then we can consunme x:Reference markup for binding.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
...
x:Name="page">
...
<DataTemplate>
<ContentView>
<ContentView.Behaviors>
<toolkit:TouchBehavior LongPressCommand="{Binding Source={x:Reference page}, Path=BindingContext.EditMessageCommand}" .../>
</ContentView.Behaviors>
...
</ContentView>
</DataTemplate>
For more info, please refer to x:Reference markup extension.
Please let me know if you have any question.