79116152

Date: 2024-10-23 01:18:34
Score: 1
Natty:
Report link

When using Bindings for a Behaviour, you may use a x:Reference Binding expression.

Let's say you have a LongPressCommand in ViewModel which the ContentPage binds to. Then you may use x:reference Binding expression for the element like below,

First, set the name of the page to "this",

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     ...
     x:Name="this">

Use x:Reference to bind,

<DataTemplate>
    ...
                <Grid.Behaviors>
                    <!--DOESN'T WORK-->
                    <toolkit:TouchBehavior LongPressCommand="{Binding BindingContext.LongPressCommand,source={x:Reference this}}"/>
                </Grid.Behaviors>
</DataTemplate>

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):
  • Starts with a question (0.5): When
  • High reputation (-1):
Posted by: Liqun Shen-MSFT