xamlxamarin.formsxamarin-community-toolkit

Xamarin.Forms how to use Xamarin Community Toolkit TouchEffect in VisualState


I am implementing a condition in my XAML using VisualState, but I don't know how I can change a property of an effect like the Xamarin Community Toolkit TouchEffect in a VisualState, any suggestions?

        <StackLayout HorizontalOptions="FillAndExpand"
                     VerticalOptions="FillAndExpand"
                     BackgroundColor="Red"
                     HeightRequest="200">
        <VisualStateManager.VisualStateGroups>
           <VisualStateGroup>
               <VisualState x:Name="test">
                   <VisualState.StateTriggers>
                      <CompareStateTrigger Property="{Binding sampleBool}" Value="true" />
                    </VisualState.StateTriggers>
              <VisualState.Setters>
<!--Here in the Property there should be some way to refer to the Command property of the TouchEffect-->
                <Setter Property="xct:TouchEffect.Command" Value="{Binding sampleCommand}" />
             </VisualState.Setters>
            </VisualState>
         </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    </StackLayout>

I've tried to reference this way, but it throws me the following error: x:Static: unable to find a public -- or accessible internal -- static field, static property, const or enum value named "Command" in "xct:TouchEffect".

<Setter Property="{x:Static xct:TouchEffect.Command}" Value="{Binding sampleCommand}" />

I have also tried to use Type but I get this error: Cannot resolve type "TouchEffect.Command"

<Setter Property="{x:Type xct:TouchEffect.Command}" Value="{Binding sampleCommand}" />

Solution

  • This was the correct way to do it, my problem was because of something else, I had the code inside a DataTemplate and had to reference the page view model.

    In a normal case this will work:

    <Setter Property="xct:TouchEffect.Command" Value="{Binding sampleCommand}" />
    

    In my case inside a DataTemplate:

    <Setter Property="xct:TouchEffect.Command" Value="{Binding Source={x:Reference SamplePage}, Path=BindingContext.sampleCommand}" />