79143249

Date: 2024-10-31 01:38:55
Score: 0.5
Natty:
Report link

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.

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Long answer (-0.5):
  • Has code block (-0.5):
  • High reputation (-1):
Posted by: Liqun Shen-MSFT