Xamarin.Forms如何在VisualState中使用Xamarin社区工具包TouchEffect



我正在使用VisualState在XAML中实现一个条件,但我不知道如何在VisualState中更改像Xamarin社区工具包TouchEffect这样的效果的属性,有什么建议吗?

<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>

我尝试过以这种方式引用,但它给我带来了以下错误:x:Static:找不到名为"的公共或可访问的内部静态字段、静态属性、常量或枚举值;命令";在";xct:触摸效果";。

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

我也尝试过使用Type,但我得到了这个错误:无法解析类型";TouchEffect.Command";

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

这是正确的方法,我的问题是因为其他原因,我的代码在DataTemplate中,必须引用页面视图模型。

在正常情况下,这将起作用:

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

在我的案例中,在DataTemplate中:

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

最新更新